I’m using the Sybase database, How do I change SQL timestamp which appears in my database in form like: 2012-03-23 11:27:04.870000 to unixtime.
I want to be able to do something like this in sql:
select time1, unix_time_function(time1) as time1_to_unixtime from mytable
Can it be done?
According to Wikipedia, UNIX time is the number of seconds elapsed since 1st Jan 1970 (not including leap seconds).
Bearing that in mind (and if I haven’t completely lost it) it should just be the difference between 1970-01-01 and your time, in seconds:
I’m not sure whether
DateDifftakes leap seconds into account, if not, there might be some adjustments needed.Documentation for
DateDiffin Sybase is here.