Search code examples
sql-serverdatetimeasp-classicdate-formatiis-8.5

Day/Month/Year date changed to Month/Day/Year in SQL


I have an old Classic ASP application that was worked perfectly, recently it was moved to window server 2012 server with IIS 8.5, the problem is that I have a form to add record with Day/Month/Year format, when the date entered as 23/06/2015 in SQL will be added correctly as 23/06/2015 but when date entered as 01/06/2015 : 1st june 2015 in SQL will be added as 06/01/2015 Month/Day/Year which will be incorrect

I checked the location and date format for the server and it was dd/mm/yyyy, and the database didn't changed since the old server SQL 2008. I searched the net and found the i need to change the IIS culture under GLOBALIZATION, but I don't know what to choose even if I chose my country still I am facing the same issue.


Solution

  • If you don't want to get into changing globalization and localization settings, the simple answer is to use the universal date input YYYYMMDD when inserting dates as strings.

    Update To expland on your comment: when changing the format of the date string in an insert/update query it does not change the format within the sql table itself.

    e.g.

    UPDATE [table]
    SET [column] = '20150716 10:22'
    WHERE Id = 7489
    

    When viewed displays the same as the other records in the table:

    enter image description here