tags:

views:

293

answers:

2

I seem to have ran into a problem I thought I had long ago solved

My web host recently changed one of the servers some of my sites are on, and this has caused problems with one site in particular that uses an access database

When inserting dates it seems to now take a date in the format DD/MM/YYYY and record it in the database as MM/DD/YYYY which as you can imagine is causing huge problems

I seem to remember before that this was an issue with how the server was setup, but cannot figure out what to change.

The servers use helm, so each website runs under its own user account, so obviously checking that my own server login is running under a UK profile makes little difference

A: 

The answer is to use parameterized queries (including insertions) and never rely on the database formatting of the data. If you have dates and times, you should always be dealing with those as dates and times instead of strings. When you query, fetch the result as a date time. When you insert/update, or provide dates within the query, provide those values as parameters with the appropriate date/time type.

(You haven't said how you're accessing the database, so it's hard to give more specific advice. I'm assuming you're doing it programmatically somehow though.)

Jon Skeet
I'm using SQL to talk to the database using ASP in a webpageUnlike mySQL for example where you format the time as yyyy-mm-dd hh:mm:ss with access you cannot do this, and it appears to automatically correct the format when it thinks it knows better, so unless you insert the date using the month name it will swpa your month and days round if it thinks they are impossible
Dave
Use SQL but with a parameterized query. Don't manually put the value into the SQL itself - use a parameter.
Jon Skeet
A: 

Sorry guys, I should have continued googling a little more before I posted here, in trying to find a quick workaround by setting the session.localid from the asp page i found the root cause/solution!

In Control Panel > Regional Settings you need to change the country/location etc to UK

Dave
This doesn't address the fundamental issue that you're putting values directly into your SQL. That's a bad idea in terms of SQL injection attacks, performance of query caching etc.
Jon Skeet
I'm not sure how that helps me? just looked at a tutorial but all i see if that it makes the sql string a little easier to construct and avoids having to strip the input for invalid characters... i don't think that would help with the date problem though because it is access that switches the dates round once it receives the data, not something that happens in sql.. you can see the same effect if you enter a date directly into the access guiIts an old legacy app too, so i don't really want to start editing every part of it that touches dates, the above solution fixes the problem. Thanks
Dave