Date Problem (1 Viewer)

ryetee

Registered User.
Local time
Today, 18:28
Joined
Jul 30, 2013
Messages
952
I have a table that store when the last end of day was performed.
It's obviously held as a date format dd/mm/yyy hh:mm:ss

When the next end of day is performed it accesses the table and gets the last date when the end of day was performed. It then uses this in a query to get the sum of goods sold since last end of day

Me.Amountsold = Nz(DSum("net", "OrdersMade", "Salesdate > #" & Me.DateAndTimeLastClosed & "#"))

This worked perfectly on Friday 30/11.
It doesn't work today on the 3/12.
I suspected and have proved the problem is that although the last end of day was stored as 03/12/2018 13:49:23 (i.e. 3rd of December) when it is used in the query it still appears to be the same but now acts as though it's the 12th March. It I change Me.DateAndTimeLastClosed to 12/03/2018 13:49:23 it works as expected.

Can I stop this behaviour? It clearly recognises dd/mm when storing (I use now() as the default on the table design) but doesn't when using it.

Heeeelp!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:28
Joined
Oct 29, 2018
Messages
21,473
Hi,

The table stores dates as a number (Double), so you can freely format it any way you want. However, expressions and VBA expects dates in either mm/dd/yyyy (U.S) or yyyy-mm-dd (ISO) format, so you’ll have to use those in code.
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 18:28
Joined
Jan 14, 2017
Messages
18,219
I'm fairly sure you asked a similar questions not long ago
You need to format all dates as mm/dd/yyyy for them to work reliably in code

Using dd/mm/yyyy, if the date is greater than the 12th, Access will interpret it correctly as the date is unambiguous. However for the first twelve days of each month, it will treat them as mm/dd/yyyy. So 03/12/2013 is treated as 12 March and your calculatin will fail
 

ryetee

Registered User.
Local time
Today, 18:28
Joined
Jul 30, 2013
Messages
952
I'm fairly sure you asked a similar questions not long ago
You need to format all dates as mm/dd/yyyy for them to work reliably in code

Using dd/mm/yyyy, if the date is greater than the 12th, Access will interpret it correctly as the date is unambiguous. However for the first twelve days of each month, it will treat them as mm/dd/yyyy. So 03/12/2013 is treated as 12 March and your calculatin will fail

I probably did!! Dates for some reason confuse the hell out of me.
Found an Allen Browne solution to convert to mm/dd using
newdateformat = Format$(stick your date variable here, "\#mm\/dd\/yyyy hh\:nn\:ss\#")
 

isladogs

MVP / VIP
Local time
Today, 18:28
Joined
Jan 14, 2017
Messages
18,219
That's the link RuralGuy was pointing you at.
 

ryetee

Registered User.
Local time
Today, 18:28
Joined
Jul 30, 2013
Messages
952
Hi,

The table stores dates as a number (Double), so you can freely format it any way you want. However, expressions and VBA expects dates in either dd/mm/yyyy (U.S) or yyyy-mm-dd (ISO) format, so you’ll have to use those in code.

Cheers.

Think you have your US date the wrong way round.
 

ryetee

Registered User.
Local time
Today, 18:28
Joined
Jul 30, 2013
Messages
952
That's the link RuralGuy was pointing you at.

Yeah spotted that. My original date query was back in 2014. No wonder I couldn't remember it! Too many brain cells have left since then. I actually found the Allen Browne solution back then. My memory is not as good as it was!

Now about dates, I'm having a problem wi.....
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:28
Joined
Oct 29, 2018
Messages
21,473
Cheers.

Think you have your US date the wrong way round.
Sorry, you got me. It was early and I was using my phone to post.

That’s my story and I am sticking with it.

Good luck with your project.
 

ryetee

Registered User.
Local time
Today, 18:28
Joined
Jul 30, 2013
Messages
952
Sorry, you got me. It was early and I was using my phone to post.

That’s my story and I am sticking with it.

Good luck with your project.

Lol, I forgive you and thanks!!
 

Users who are viewing this thread

Top Bottom