Localization issue with date formats using Classic ASP on webmatrix 2

1.1k Views Asked by At

I am getting a bit worked up here. I am working on new site in Classic Asp.

Built everything and all is working fine and now comes the time to test with some data. The moment we come to date related data everything goes crazy.

i run a query on my SQL CE that comes with WebMatrix 2, and inserted the date into the field using Getdate(), and checked it out, the format is mm/dd/yyyy.

now on the webpage if i do a response.write Date(), its in dd/mm/yyyy format.

FormatDateTime(nDate,vbshortdate) returns the date in yyyy/mm/dd format.

Ok that was all about the background and facts.

So now i have the date in the field called newDate. i populate it to my text box using a variable. Now if i try to update the db its an error. I response.write the sql query, and the date is now string in the right to left(arabic) style.

I do believe this may be a localization issue, if someone can help me out of this predicament.

I must also add, that in my webpages i have been using charset=utf-8.

many thanks

2

There are 2 best solutions below

1
On

SQL CE doesn't "format" a date when it stores it as such. WebMatrix formats it for display in the Database tools. If you want to control the display format of a date in a browser using VBScript, you have a range of options. See Date Formatting in VBScript. Also see Can I make VBScript Format Dates For Me.

0
On

I used the following code in a form where the data is store in a table named Employees:

@{
var record = UrlData[0].AsInt();
var id=Request["id"];
var db = Database.Open("StarterSite");
var SQLSELECT = "SELECT * FROM Employees where Id=@0";

// Select the requested record //

var emp = db.QuerySingle(SQLSELECT,id);
var EmployeeDOB = emp.DateOfBirth;

EmployeeDOB=Request["formDOB" ];

// Update the database with data from the form //

var SQLUPDATE = "UPDATE Employees Set EmployeeDOB=@1 where Id=@0";
    db.Execute(SQLUPDATE, EmployeeId, 
    EmployeeDOB);
}
<form method="post">

<label for="formDOB" @if (!ModelState.IsValidField("formDOB")) {<text>class="error-     label"</text>} >DOB:</label>
<input  type="date" name="formDOB" value="@EmployeeDOB.ToString("MM/dd/yyyy")" style="display:inline-block;margin-top:5px;margin-bottom:5px;max-width:80px;" onblur=' '/>@Html.ValidationMessage("formDOB")<br />

EmployeeDOB is declared in the table as a datatime.

The input field is displayed as a date in format MM/dd/yy without the time, but stored in the table as date time, i.e., 11/22/2012 8:00:00 PM.