Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date extraction

Status
Not open for further replies.

Peps

Programmer
Feb 11, 2001
140
ES
Hi,

Any ideas on how to extract a part of a date, I need "7" form 2007, "8" from 2008, and so on. I have been using the below which has worked well until now:


AnyString = DateField
MyStr = Right(AnyString, 1)
NewValue = MyStr

While all is ok when using the date format "DD/MM"/YYYY" all the problems start when some users have the Windows format "YYYY/MM/DD" this is due to the fact that some users need this format for some other system applications which do not recognize "DD/MM/YYYY".

I need to be able to extract the 7 form 2007 regardless of the date format being used.


Thanks to all,





 
Just a thought - couldn't you use the Format() function to format the date the way you want it and then grab right(1) of the year

Or, use the Year function to just extract the year and then get right(1) of that. For example, Year(#2008/11/21#) returns 2008.
 
Nice one, the second option with the right grab works on any date format.

Cheers,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top