Localizing a Date from a Record Set in Classic ASP

In order to improve Canadian customer service, we are trying to localize the dates displayed on some of the old classic ASP pages. We successfully started using the SetLocale () vb script function - we correctly process user input dates.

However, I expected that the date returned by ADODB.Recordset would respect the locale. Consider the following code:

SetLocale 4105 ''' ' Get a list of Employees SQL = "SELECT Firstname, Lastname, HireDate FROM Employee" Set conn = Server.CreateObject("ADODB.Connection") conn.Open Application("ConnectionString") Set cmd = Server.CreateObject("ADODB.Command") cmd.ActiveConnection = conn cmd.CommandType = 1 cmd.CommandText = SQL Set rst = Server.CreateObject("ADODB.Recordset") rst.CursorLocation = 3 Set rst = cmd.Execute 

When a HireDate column is written to a page, it is displayed as MM / DD / YYYY (the format used by our servers).

A few notes:

  • We need to serve both American and Canadian clients on the same server (therefore changing the localization / region of the server is not an option). This should be a clean software solution.
  • I noticed that TypeName of rst ("HireDate") - "Field" is not a date, as I expected.

What is the correct way to localize the date values ​​coming from the SQL server in this scenario?

+4
source share
2 answers

I think you still have to use the FormatDateTime function to display it correctly.

Try

 FormatDateTime(rst("HireDate").Value, vbShortDate) 
+3
source

rst ("HireDate") is a field

rst ("HireDate"). Value will be Date

rst ("HireDate"). Value.ToString () will return the date as a string in the locale of the machine on which the statement is running, the IIS machine almost certainly works, on which the Server sql ruuning on box may or may not be.

See GetLocale / SetLocale uis in one way, the other in client-side jaavscript to display dates as strings.

+1
source

Source: https://habr.com/ru/post/1387208/


All Articles