Date Issue

aziz rasul

Active member
Local time
Today, 23:42
Joined
Jun 26, 2000
Messages
1,935
When I used

Code:
Format(Now(), "dd/mm/yyyy hh:nn:ss") > Format(#8/20/2013 4:41:00 PM#, "dd/mm/yyyy hh:nn:ss")

in the latter part of last month, the above code worked. But now it only works if I change the code to

Code:
Format(Now(), "mm/dd/yyyy hh:nn:ss") > Format(#8/20/2013 4:41:00 PM#, "mm/dd/yyyy hh:nn:ss")

The date\time #8/20/2013 4:41:00 PM# can change depending on which date\time I'm running this snippet of code.

How can I change the code so that it will always work irrespective of the date I use?
 
I am not sure if this is the right way, but Access stores date/time in Double precision. Dates the integer part and decimal part being the time.. What I normally do is..
Code:
CDbl(Now) > CDbl(#8/20/2013 4:41:00 PM#)
As
Code:
? CDbl(Now)
 41520.4662731482 
? CDbl(#8/20/2013 4:41:00 PM#)
 41506.6951388889
Its easier that way.. ;)
 
using Format(Now(), "mm/dd/yyyy hh:nn:ss") should always work
 
Format creates a. String and therefore you are comparing strings , always dodgy, and why 1/09/2013 was less than 20/08/2013 if comparing strings you need to use yyyy/mm/ dd and ensure leading zeroes are present but obviously Paul's approach over comes these difficulties.
Another approach is to use Datediff on seconds and compare the result against 0

Brian
 

Users who are viewing this thread

Back
Top Bottom