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 645715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:32:00+00:00 2026-05-13T21:32:00+00:00

I am saving a TimeSpan (from .NET) value in my db as BIGINT in

  • 0

I am saving a TimeSpan (from .NET) value in my db as BIGINT in SQL Server (saving the Ticks property). I want to know how to convert this BIGINT value to a DATETIME value in SQL Server (not in .NET). Any ideas?

Cheers

EDIT:

I am using NHibernate to map a TimeSpan property I have, and it persists the Ticks property. I use it for relative hours (or minutes) control over some date.

Internally in the system everything is fine, this conversion isn’t needed. However, when performing random queries in SQL Server, it is hard to understand the persisted form of a TimeSpan. So, a function where I pass the Ticks value and a DateTime is returned would give the amount in hours, minutes and seconds that that TimeSpan represents.

  • 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-05-13T21:32:01+00:00Added an answer on May 13, 2026 at 9:32 pm

    I’m not sure how accurate this will be with the seconds, but you could try something like:

    Declare @TickValue bigint
    Declare @Days float
    
    Set @TickValue = 634024345696365272 
    Select @Days = @TickValue * POWER(10.00000000000,-7) / 60 / 60 / 24
    
    Select DATEADD(d, Cast(@Days As int), Cast('0001-01-01' As DATE)) 
        + Cast( (@Days - FLOOR(@Days)) As DateTime)
    

    Actually another way that would work in SQL 2005 is to note that the the number of ticks from 0001-01-01 to 1900-01-01 is 599266080000000000. With that you could do:

    Declare @TickOf19000101 bigint
    Declare @TickValue bigint
    Declare @Minutes float
    
    Set @TickOf19000101  = 599266080000000000
    Set @TickValue = DATEDIFF(mi, 0 ,CURRENT_TIMESTAMP) * Cast(60 As BigInt) 
                       * POWER(10.00000000000,7) + @TickOf19000101
    
    Select @TickValue
    Select @Minutes = (@TickValue - @TickOf19000101) * POWER(10.00000000000,-7) / 60
    
    Select @Minutes
    Select DATEADD(MI, @Minutes, '1900-01-01')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert DateTime+TimeZoneInfo into DateTimeOffset. How do I do this? I assume
After saving a String value into memcached using the Danga client, I attempted to
between saving a key name like this for(var key in this.data) { var key_name
I'm saving the location of my application but it does not want to keep
Saving the file: FileOutputStream fo = null; try { fo = this.openFileOutput(test.png, Context.MODE_WORLD_READABLE); }
A quick question about saving data in symfony 2. I have this method (just
I am saving a number eg. 000001 in a SQL TEXT field which causes
I'm saving my color in db in int value. int icolor = System.Drawing.Color.Red.ToArgb(); //result:
I need help saving a PPM file in C/C++. I want to save an
I am saving some data in order using array s, and I want to

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.