Dates (1 Viewer)

k209310

Registered User.
Local time
Today, 07:59
Joined
Aug 14, 2002
Messages
185
CurrentYear = Right(Date, 2)

It might just be but does the above string not do what its supposed to?

If you display the result of the string in a message box it displays 02/01/1900. If i just put in Date then i get the correct result. Does anybody have any idea whay this is happeneing? I have CurerntYear declared as a date.

Cheers

Chris
 

k209310

Registered User.
Local time
Today, 07:59
Joined
Aug 14, 2002
Messages
185
Thanks for the reply but it didnt seem to work

below is the code im using


Dim CurrentYear As Date
CurrentYear = Date
CurrentYear = Right(CurrentYear, 2)

MsgBox CurrentYear


I had tried using CurrentYear = Year([CurrentYear]) as you and the help files both suggested but i had no luck. It displayed the date 25/06/1905 (my ytem date is correct). Any ideas??

Cheers

Chris
 

Mile-O

Back once again...
Local time
Today, 07:59
Joined
Dec 10, 2002
Messages
11,316
:confused:

CurrentYear = Format(Year([MyDate]), "yyyy")

Personally, if I only needed the year I'd store it in an Integer.
 

k209310

Registered User.
Local time
Today, 07:59
Joined
Aug 14, 2002
Messages
185
Cheers mike

that example displays 19/03/1905

Does anybody have any idea whay this is happeneing???
 

k209310

Registered User.
Local time
Today, 07:59
Joined
Aug 14, 2002
Messages
185
I have managed to get Right(Date, 2) to display the last two didgits of the year however if i store them in the table as integers as you suggested the leading Zero is deleted.

Do you know any way around this?
 

k209310

Registered User.
Local time
Today, 07:59
Joined
Aug 14, 2002
Messages
185
Thanks everyone got it sorted now. Still dont know whay the dates mess up tho. If anyone has any idea id wouldnt mind some adice on it.

Cheers anyway

chris
 

Mile-O

Back once again...
Local time
Today, 07:59
Joined
Dec 10, 2002
Messages
11,316
I would guess because your variable is a date value, you are using a string function to get the year from it (i.e 03) and only put 03 into a date.

Try this in Excel: put 3 into a cell. Change the cell's format to dd-mm-yy and you'll see why you are getting the result you have.

Today's date is: 37742 as an integer value.
 

Users who are viewing this thread

Top Bottom