简体   繁体   中英

Date formatting reverting in Access 2016 on Windows 10/IIS/Classic ASP

hopefully I can explain this problem in enough detail for someone to let me know of a possible solution, or at least let me know there isn't a fix (other than the one I mention below).

Ok, I am migrating from the following environment:

Windows XP/Access 2003/Classic ASP/IIS

to:

Windows 10 Pro/Access 2016/Classic ASP/IIS

Basically I have a local website running in IIS written in Classic ASP. The pages run in a web browser and there are plenty of inserts and updates occurring in an Access DB. The Win XP environment is setup as located in Australia, however I have all formatting as US based, so that all formatting occurs in "mm/dd/yyyy".

In Windows XP, I can run a query update in ASP as follows treating the date as a string:

    theDate = Now()
    SQLStmt =   "UPDATE tTable SET DateField ='" & theDate & "' WHERE DateID=1"

and it works just fine, as in if the date is October 1st 2017 it will appear in the Access DB table as 10/01/2017. The date type of the date field (in the above example, DateField) is of type "Date/Time".

So, I installed Windows 10 Pro, setup IIS with Classic ASP, created a virtual directory, moved over all the files from Win XP, and went about changing all the date settings throughout Win 10 to be US format. I have also changed the "Locale ID" under "Configure properties for ASP applications" to 1033 in IIS. Access DB is being used without converting to Access 2016 (so it can be moved back to Win XP environment if need be).

However, running the above query results in the date going into Access DB as "01/10/2017".

So I setup the following code to test out the date formatting:

    theDate_01 = Now()

    theDateTime = FormatDateTime(theDate_01,3)

    theDate_02 = Year(theDate_01)&"-"&Month(theDate_01)&"-"&Day(theDate_01)&" "&theDateTime

    SQLStmt =   "UPDATE tDateTest SET "
    SQLStmt =   SQLStmt & "theDate='" & theDate_01 & "'"
    SQLStmt =   SQLStmt & " WHERE DateID=1"
    Set RS = conntemp.execute(SQLStmt)

    SQLStmt =   "UPDATE tDateTest SET "
    SQLStmt =   SQLStmt & "theDate='" & theDate_02 & "'"
    SQLStmt =   SQLStmt & " WHERE DateID=2"     
    Set RS = conntemp.execute(SQLStmt)

%>

Basically I have a table called tDateTest in Access, with two columns DateID and theDate.

The result from running the above code is that theDate_01 is inserted incorrectly (that is, in AU date format) whilst theDate_02, because I've turned it first into yyyy-mm-dd format, does get inserted correctly.

Now with hindsight I would have done this whenever I was updating/inserting a date, however I am in the situation where I have many pages of code with many date updates/inserts that would need to be changed.

Is there any way to have the environment in Windows 10 behave the way it has been in Win XP, that a query with a date string simply inserts/update into an Access date/time field in the format I've specified throughout Win 10/IIS, in US format?

First, you might be able to simply do:

SQLStmt = "UPDATE tTable SET DateField = Now() WHERE DateID=1"

If not, force the format and use octothorpes:

SQLStmt = "UPDATE tTable SET DateField = #" & Format(theDate, "yyyy\/mm\/dd") & "# WHERE DateID=1"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM