Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ASP / Database Access / July 2008



Tip: Looking for answers? Try searching our database.

More Access date trouble

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Giles - 11 Jul 2008 00:05 GMT
I use a german rented virtual server. MSAccess dates (entered by an SQL
INSERT) appear in the database table (when downloaded and opened as Access
on my local UK machine) appear as mm/dd/yy. But if I then update it locally
(e.g. via localhost) those dates appear as dd/mm/yy. The raw date in both
cases is formatted as yyyy-mm-dd hh:mm:ss before being inserted.
<%SetLocale(1033)%> is used on both the server and localhost page.
Is there a way to make the server-based Access use a UK date/time format, or
does Access always use the Regional Settings of whichever machine it is on
at the time? (I can't access the windows settings on the server)
Is there any sense in using a (double) number like 20082207103000 for date
time?
Thanks, Giles
Old Pedant - 11 Jul 2008 00:29 GMT
Access *ONLY* understands USA dates.  MM/DD/YYYY

Sorry, but that's a fact of life.

Okay, it's also not quite true.

If you give it a date such as
    23/6/2008
then it says "Oh, 23 is too large to be a month number, so it must be a day
numbers, so I'll change and assume DD/MM/YYYY format."

But if you give it
   7/6/2008
it will *ALWAYS* assume you mean July 6, 2008.  USA form.

Unlike SQL Server, there is no way to tell Access what format you are using
*AND* the Locale you are using has no impact on the Access SQL query.  I
know.  Ugly.

HOWEVER...

However, there *IS* a universal solution:  Give Access the date in
YYYY/MM/DD format!!  Just as it changes to DD/MM/YYYY when the first number
is greater than 12, it *also* changes to YYYY/MM/DD format when the first
number is greater then 31!!!

In VBScript/ASP this is easy:

<%
Function ISODate( dt )
   Dim temp : temp = "NULL"
   If IsDate(dt) Then
       dt = CDate(dt)
       temp = "#" & Year(dt) & "/" & Month(dt) & "/" & Day(dt)
       If DateValue(dt) <> dt Then temp = temp & " " & TimeValue(dt)
       ISODate = temp & "#"
   End If
End Function
%>

Now, in constructing your SQL queries, you can do things like
    SQL = "SELECT * FROM table WHERE someDate > " & ISODate(xyz)
or
    SQL = "INSERT INTO table (someDate) VALUES(" & ISODate(fooraw) & ")"
Notice how the function puts the #...# in place for you.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.