How can I convert UNIX timestamp (bigint) to DateTime in SQL Server?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
Like this
add the Unix (epoch) datetime to the base date in seconds
this will get it for now (2010-05-25 07:56:23.000)
If you want to go reverse, take a look at this http://wiki.lessthandot.com/index.php/Epoch_Date
This worked for me:
In case any one wonders why 1970-01-01 ,This is called Epoch time.Below is a quote from wikipedia
Adding n seconds to
1970-01-01
will give you a UTC date because n, the Unix timestamp, is the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970.In SQL Server 2016, you can convert one time zone to another using
AT TIME ZONE
. You just need to know the name of the time zone in Windows standard format:Or simply:
Notes:
DATETIMEOFFSET
toDATETIME
.