Converting MSSQL GetUTCDate () to PHP / Unix / MySQL Ticks

I am inserting DateTime into MsSQL using the GetUTCDate () function provided by MsSQL.

I need to convert the time in C # to show it as a Unix / MySQL integer so that it can eventually be manipulated with PHP.

I believe the Unix / PHP / MySQL marks start at 1/1/1970, but I'm not sure how to convert the MsSql / C # equiv to this unix standard.

Any help would be appreciated.

+1


source to share


2 answers


DateTime dt = something; //Get from db

TimeSpan ts = dt - new DateTime(1,1,1970); // off the top of my head, check order of params

long ticks = ts.TotalTicks; // again off the top of my head, check property name

      



0


source


You can do this in MSSQL relatively easily. For the current date:

SELECT DATEDIFF(s, CONVERT(DATETIME, '1970-01-01'), GETUTCDATE())

      



returns INT the number of seconds since 1/1/1970, which is the Unix timestamp.

+3


source







All Articles