To convert a datetime string value like “YYYY-MM-DD HH:MM:SS” to a Unix timestamp (the seconds from 01/01/1970 to the input datetime) You can use a conversion function as the following:
Function ConvertToUnixTimeStamp(input_datetime) 'As String Dim d d = CDate(input_datetime) ConvertToUnixTimeStamp = CStr(DateDiff("s", "01/01/1970 00:00:00", d)) End Function
Then, to get back the datetime from the Unix timestamp use the following code:
Function ConvertUnixTimeStampToDateTime(input_unix_timestamp) 'As String [regular datetime] ConvertUnixTimeStampToDateTime = CStr(DateAdd("s", input_unix_timestamp, "01/01/1970 00:00:00")) End Function
3 Responses
Viet Anh Auto
I had the same problem. You saved my day. Thanks so much!
Ashwani
what if need to convert from filetime to date in classic asp
China Gittler
Hello there, You have done an excellent job. I’ll certainly digg it and personally recommend to my friends. I’m sure they will be benefited from this web site.|