danny1620
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
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 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)
ASKER
I am sorry its the otherway .. I need to check GMT date against Unix Date by converting GMT to UNIX..
just reverse it:
DATEDIFF(s, '1970-01-01 00:00:00', UnixTime)
DATEDIFF(s, '1970-01-01 00:00:00', UnixTime)
correction:
UnixTime = DATEDIFF(s, '1970-01-01 00:00:00',MyTime)
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())
*
FROM
[YOUR TABLE]
WHERE
Convert(datetime, dateadd(s, ,<YOUR DATE TIME COLUMN IN UNIX>, '19700101')) >= dateadd(dd, -30, getdate())
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys
eg.
SELECT dateadd(s, 1113211532, '19700101')
returns; 2005-04-11 09:25:32.000