Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:02:23+00:00 2026-06-17T19:02:23+00:00

I have found only one similar question but for MySQL. I was working on

  • 0

I have found only one similar question but for MySQL.

I was working on a web service and had to query the database (MS SQL server). Since I couldn’t get the right result I decided to test the query via a SQL client. The web service uses Hibernate to access the DB and all time values are always represented as long values (unix epoch time). In order to test it, I needed to convert the unix timestamp to TSQL timestamp. This is what I came up with:

select dateadd(ms,123,'1970-01-01 00:00:00.0');

which outputs:

1970-01-01 00:00:00.123

But, my actual data was a bit bigger

select dateadd(ms,1359016610667 ,'1970-01-01 00:00:00.0');

which outputs:

Error code 0, SQL state 22001: Data truncation
Error code 8115, SQL state 22003: Arithmetic overflow error converting expression to data type int.

So, I tried:

select dateadd(ms,CAST (1359016610667 AS BIGINT) ,'1970-01-01 00:00:00.0');

which outputs the exact same error. Just to be safe I tried:

select CAST (1359016610667 AS BIGINT) 

which outputs:

1359016610667

I made sure that java long is equivalent to TSQL bigint – they are both 8 B long. Rereading the dateadd() documentation revealed the following:

DATEADD (datepart , number , date )
….
number
Is an expression that can be resolved to an int that is added to a datepart of date. User-defined variables are valid.

If I understand this correctly, it means that this approach can not be used to convert a unix timestamp to TSQL timestamp, which is, well, pardon my language, but just plain stupid.

My questions are:

  • is my interpretation of this situation correct?
  • is there any other one-liner to do this conversion in TSQL ?

PS
modifying the date argument ('1970-01-01 00:00:00.0') is not acceptable as solution. I’m debugging and I don’t want to recalculate the miliseconds along 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:02:25+00:00Added an answer on June 17, 2026 at 7:02 pm

    Easy, first add whole days, then add the remaining ms. There are 86,400,000 milliseconds in a day.

    declare @unixTS bigint
    set @unixTS = 1359016610667
    
    
    select dateadd(ms, @unixTS%(3600*24*1000), 
        dateadd(day, @unixTS/(3600*24*1000), '1970-01-01 00:00:00.0')
    )
    

    The result is 2013-01-24 08:36:50.667

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The only similar question I have found is: Insert php boolean into mysql bit
My question is similar to this one , but is different enough that I
My problem is similar to the one in this question, but the opposite. How
I have found only two methods (SaveFile, LoadFile) which save in a file. How
The SSE shift instructions I have found can only shift by the same amount
How can I apply a ringtone to only the selected contact? I have found
I have looked all around and only found solutions for python 2.6 and earlier,
I'll preface this question with the note that I have looked at this similar
(Only managed to find one other question on this - Object persistence strategy for
I have a table in SQL Server 2000 that I am trying to query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.