Link to home
Start Free TrialLog in
Avatar of danny1620
danny1620Flag for United States of America

asked on

How to convert Unixtime to GMTime in SQL Server

Hi guys i am trying to get last 30 days data but its unix datetime So,how do i convert and get the data for last days on a daily basis..

Thanks
SOLUTION
Avatar of ezraa
ezraa

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SELECT dateadd(s, ,<YOUR DATE TIME IN UNIX>, '19700101')
eg.
SELECT dateadd(s, 1113211532, '19700101')

returns; 2005-04-11 09:25:32.000
Avatar of danny1620

ASKER

Thanks Guys ...
I was using the below SQL to get the last 30 days data .. How can i use the same to get the last 30days data which has uNIX timestamp

SELECT ID Where Date >= DATEADD(D,DATEDIFF(DAY, 0 ,GETDATE())-30, 0)
and Date < DATEADD(D,DATEDIFF(DAY, 0 ,GETDATE()), 0)
I am sorry its the otherway .. I need to check GMT date against Unix Date by converting GMT to UNIX..
Avatar of ezraa
ezraa

just reverse it:

DATEDIFF(s, '1970-01-01 00:00:00', UnixTime)
correction:

UnixTime  = DATEDIFF(s, '1970-01-01 00:00:00',MyTime)
SELECT
 *
FROM
 [YOUR TABLE]
WHERE
  Convert(datetime, dateadd(s, ,<YOUR DATE TIME COLUMN IN UNIX>, '19700101')) >= dateadd(dd, -30, getdate())
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks guys