Sunday, July 12, 2009

VBScript / ASP Function to Convert Dates to/from MySQL


' MySqlDate(Now, 1) --> "2008-02-20"
' MySqlDate(Now, 2) --> "2/20/2008"

Function MySqlDate( d, dir )
If Not isDate( d ) Then d = Date()
Dim strNewDate
Select Case dir
Case 1:
'=== store in db
strNewDate = Year( d ) & "-" & Month( d ) & "-" & Day( d )
Case 2:
'=== use with asp
strNewDate = Month( d )& "/" & Day( d ) & "/" & Year( d )
strNewDate = cDate( strNewDate )
End Select
mysqlDate = strNewDate
End Function

No comments:

Post a Comment