Convert Unix time from IPFix to datetime in SQL [duplicate] - sql

This question already has answers here:
converting Epoch timestamp to sql server(human readable format)
(2 answers)
SQL: Using DATEADD with bigints
(6 answers)
Closed 8 years ago.
I have an IPFix timestamp which appears to be in Unix time. My SQL code is:
update
temp_ipfix
set FlowStartTimeDT = dateadd(S, FlowStartTime, '1970-01-01 00:00:00')
Where FlowStartTime is the column containing the Unix timestamp.
A sample timestamp is 1410435197783
The error I'm getting is:
Arithmetic overflow error for type int, value = 1410435197783.000000.
The statement has been terminated
I tried the suggestions linked to this page, but the results are incorrect. Month and Day are correct, but year is 2034.
select dateadd(s, (flowstoptime/1000), '1990-01-01 00:00:00') from temp_unix

Related

Writing user friendly queries in oracle SQL having time in UNIX time format [duplicate]

This question already has answers here:
How to convert timestamp with milliseconds to date in Oracle
(1 answer)
Group by with Unix time stamps
(1 answer)
Closed 9 months ago.
I have a Oracle DB in which the time is stored in UNIX time format. Currently I write queries having UNIX time format. for example.
(TIME >= '1648771200' and TIME <= '1651320000')
I want the query to be user friendly having conventional date format,
(TIME >= '2022-05-10 12:00:00' and TIME <= '2022-05-20 12:00:00')
Is it possible to do it ? Thank you.

How to Convert EPOCH UNIX datetime to SQL format with SQL Server [duplicate]

This question already has answers here:
converting Epoch timestamp to sql server(human readable format)
(2 answers)
Convert unix epoch timestamp to TSQL datetime
(2 answers)
Closed 2 years ago.
I have the following table with epch unix datetime stamps. Can someone let me know if there is SQL query or function that will allow me to convert / replace the the UNIX EPOCH time to SQL format
An epoch timestamp represents the number of seconds elapsed since January 1st, 1970. In SQL Server, you can use dateadd() to perform this computation:
dateadd(second, start_timeslot_unix, '19700101') start_timeslot_datetime
If your epochs are expressed in milliseconds instead of seconds, then: dateadd(second, start_timeslot_unix / 1000, '19700101').

Postgresql sql query convert time in second [duplicate]

This question already has an answer here:
Convert timestamp column values to epoch in PostgreSQL select query
(1 answer)
Closed 3 years ago.
I have MySQL DB and i am using following syntax to convert my datetime type in second
select UNIX_TIMESTAMP(created_at) as time_sec, blah..blah..
But now i have other postgresql DB which has timestamp with time zone type so how do i convert that time in second with my select query?
2018-04-18 18:27:48.96283+00 This is this format of timestamp in table which i want to convert in seconds
you can use
select extract(epoch from created_at) as time_sec from tsepok
db<>fiddle here
more docs here

Convert date to MM//DD HH/MM [duplicate]

This question already has answers here:
Sql Server string to date conversion
(16 answers)
Closed 5 years ago.
How do you convert date to MM/DD HH/MM
example: 04-05 12:42
Since you are on SQL Server 2012, use FORMAT:
SELECT FORMAT(GETDATE(), 'MM-dd HH:mm')
Try using the MONTH, DAY, HOUR, MINUTE functions in T-SQL and concatenate your results into a string form like:
CONCAT(STRING(HOUR(created_at)), ':', RIGHT(STRING(MINUTE(created_at)), 3)) AS hour_min
Where the created_at is your timestamp column. Hope this helps!

How to get first hour of today in SQL Server? [duplicate]

This question already has answers here:
How to return only the Date from a SQL Server DateTime datatype
(46 answers)
Closed 5 years ago.
I need to obtain today's date but instead of current time I need the first time of the date.
WRONG WAY:
'4/7/2017 4:50:13 PM'
as result of getdate() function
RIGHT WAY:
'4/7/2017 00:00:00 AM'
Thanks for your help
How about this
select cast(cast(getdate() as date) as datetime)