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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If Date Greater than - 8

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Whats the best way to compare the pc date to a hard coded reference date to drive an If/Else case. Many thanks
 
Many thanks Hypetia for the followup. I tried

Dim D As Date
D = DateSerial(3, 2, 1) 'always Feb 2, 2003

But it does change its output against local settings.

I can only set English(United Kingdom) or English(United States) settings on my pc, probably software related?.

Anyway, I do find I can do what I like to the local settings and it does not change Format(Date, "DD/MM/YYYY"), alsways returns a predicted output.

Therefore I am going to use:
date1 = "01-04-2004"
date2 = Format(Date, "DD/MM/YYYY")

keeping them as strings, split them up and compare Month and Year set/check expiry date limits.

Thanks again.



 
First note that the comments in front of the DateSerial function are wrong. It should read as;
[tt]D = DateSerial(3, 2, 1) 'always Feb [tt]1[/tt], 2003[/tt]

>But it does change its output against local settings.
Of couse the output representation is locale dependent... until you format it using Format function.

I was talking about the input format; how the date is interpreted. Which number is treated as month and which as day. It becomes locale dependent if you assign string dates and locale independent if you use genuine date literals using # symbols.

The date output using Format function is locale independent as you explicitly specify the format yourself using M,D and Y. On the other hand the output of FormatDateTime function is locale dependent as it uses named formats which are based on system settings.

Instead of using string dates, I still recommend you to use date literals, because of the following reasons.
1. "01-04-2004" may be interpreted as April 1 or January 4. However, #4/1/2004# will always be interpreted as April 1.
2. Using actual date variables, you gain the flexibility of manipulating dates as numbers as I described above; which is not possible with strings.
 
Many thanks agin. Tries another star, but don't think it will give it. Now I get it, and will use date literals as you suggest. Many thanks for all your help. Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top