Access & Dates makes my head hurt.

Comfy

Well-known Member
Joined
Dec 21, 2009
Messages
3,386
I'm extracting records to a recordset and looping through each record.

I would like clarification on something as I'm not quite sure I have the correct Query.

My Table contains a DateTime Column formatted as EU General dd/mm/yyyy hh:nn:ss (We'll use 03/05/2015 00:00:01 for this example)

I'm using this DateTime in a sub query.

SQLstr = "Select * From Table2 Where [dDate] >= #" & rSet!DateTime &"#;"

which becomes "Select * From Table2 Where [dDate] >= #03/05/2015 00:00:01#;"

Due to Access' assumption that this is a US date format mm/dd/yyyy hh:nn:ss I get the incorrect results.

To fix this I have used "Select * From Table2 Where [dDate] >= CDate('" & rSet!DateTime &"');"

which becomes "Select * From Table2 Where [dDate] >= CDate('03/05/2015 00:00:01');"

But I am not sure that this is correct.

Do I have to use DateSerial to build the correct date or would formatting the Date to mm/dd/yyyy be sufficient?
 
In Databases of whatever flavour, always use ISO dates (yyyy-mm-dd) it's universal and works everywhere. My personal opinion is that DB designers shouldn't recognise local variations as it just creates confusion (especially since MS is incorrectly under the impression that most of the world uses mm/dd)
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I haven't found Access to be particularly good with yyyy-mm-dd as a format, sadly. I prefer dd-mmm-yyyy with Access.
 
Upvote 0

Forum statistics

Threads
1,221,864
Messages
6,162,497
Members
451,770
Latest member
tsalaki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top