Convert MSSQL timestamp to UNIX timestamp
Today I had to pull a number of datetime fields from MSSQL and update records in MySQL with them, using PHP.
The most efficient way to convert the date-time field to a unix timestamp for inputting into MySQL was the following:
DATEDIFF(s, "19700101", ro_job_date) as ro_job_date,
In this example the field was ro_job_date
19700101 is the 1st Jan 1970, the “unix epoch”.
I didnt have to convert from unix timestamp to MSSQL datetime, but researching the above turned up this snippet for that:
SELECT DATEADD(s, unix_timestamp, '19700101')
where unix_timestamp is your timestamp field