Convert a Date to ISO format : Active Server Pages (ASP)

This short tutorial will show you how to take any date, either in a database or passed in your page, and split it up and reassemble in the ISO format.

This can be very helpful in querying against your database, as it does not require the database to be set to your localised language and thus Date format, I have also found Access plays a lot nicer when the Date is in ISO format.


I have included two examples, the first is using a recordset value, and needs to be placed around the output, not in the top of the page if you have multiple records, as it will set all values for every record to the same value.

DOBDate = DatePart(“d”, rsreportdetails(“ClientDOB”))
If DOBDate < 10 Then
DOBDate = “0” & DOBDate
End If
DOBMonth = DatePart(“m”, rsreportdetails(“ClientDOB”))
If DOBMonth < 10 Then
DOBMonth = “0” & DOBMonth
End If
DOBYear = DatePart(“yyyy”, rsreportdetails(“ClientDOB”))
ISODOB = DOBYear & “-” & DOBMonth & “-” & DOBDate

This example took the column ClientDOB from the recordset rsreportdetails, and split it up, into Date, Month and Year, then reassembled it in the ISO format of YYYY-MM-DD. Using Response.Write ISODOB displays the output on the page.

My second example uses a Form value or value passed in the URL.

Dim ISOStartDate
varSDate = DatePart(“d”, Request(“StartDate”))
If varSDate < 10 Then
varSDate = “0” & varSDate
End If
varSMonth = DatePart(“m”, Request(“StartDate”))
If varSMonth < 10 Then
varSMonth = “0” & varSMonth
End If
varSYear = DatePart(“yyyy”, Request(“StartDate”))
ISOStartDate = varSYear & “-” & varSMonth & “-” & varSDate

again we are splitting up the date and reassembling in the ISO format. You would then in your recordset use ISOStartDate as the value of the definition for checking against the database.