SQL SERVER – Converting Unix TimeStamp to DateTime

There is a very easy method to convert Unix TimeStamp to DateTime. Let us learn that in today’s blog post.

Here is a very simple example of it.

Unix TimeStamp

DECLARE @UnixDate BIGINT = 1392349571299
DATEADD(s, @UnixDate / 1000, '1970-01-01')) AS DATETIME2(3))

When you run the script above it will display the result as 2014-02-14 03:46:11.300

Yes, that’s it. It is that simple to convert Unix TimeStamp to Datetime.

Learn MySQL – Learning Path

Here are six-part blog post series I have written based on my last 10 years of experience helping with the Comprehensive Database Performance Health Check. I strongly recommend you to read them as they walk you through my business model.

If you have any questions, you can always reach out to me on Twitter.

Reference: Pinal Dave (http://blog.SQLAuthority.com)

Exit mobile version