Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Madam/Sir,
Good day,

I have database in SQL server and there is column for time but in UNIX syntax, I tried to convert it and it worked for me by this code :
SQL
Select
    dateadd(S, [TIMESTAMP_S], '1970-01-01'),Value
From [table_Name]


but my main problem is when I am trying to get last 24 hours from table I cant get it after converting and I face error.

My code with converting and get last 24 hours is :

SQL
select  DATEADD(ss, TIMESTAMP_S, '1970-01-01 00:00') AS ConvertedDate  from  Table_Name
where  TIMESTAMP_S between dateadd(hour, -24, CURRENT_TIMESTAMP)
AND CURRENT_TIMESTAMP


error is :

C#
Msg 8115, Level 16, State 2, Line 18
Arithmetic overflow error converting expression to data type datetime.


thanx in advanse.

What I have tried:

Convert Unix time code:

SQL
Select
    dateadd(S, [TIMESTAMP_S], '1970-01-01'),Value
From [table_Name]


convert Unix time and get last 24 hours code:

SQL
select  DATEADD(ss, TIMESTAMP_S, '1970-01-01 00:00') AS ConvertedDate  from  Table_Name
where  TIMESTAMP_S between dateadd(hour, -24, CURRENT_TIMESTAMP)
AND CURRENT_TIMESTAMP
Posted
Comments
CHill60 12-Nov-16 21:15pm    
You've said you have a column for time "in UNIX syntax" ... so you've stored that time as a varchar?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900