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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:39:32+00:00 2026-05-25T14:39:32+00:00

I have a SQL server database and I am pulling dates from it and

  • 0

I have a SQL server database and I am pulling dates from it and converting the type of timestamp_t into Int64 as such:

Int64 from_timestamp_t(dtl::timestamp_t& t)
{
    // create a new posix time structure
    boost::posix_time::ptime pt
    (
    boost::gregorian::date           ( t.year, t.month, t.day),
    boost::posix_time::time_duration ( t.hour, t.minute, t.second, t.fraction )
    );

    ptime epoch(date(1970, Jan, 1));
    boost::posix_time::time_duration fromEpoch = pt - epoch;

    // return it to caller
    return fromEpoch.total_milliseconds();
}

I attempt to convert back to a boost ptime from an Int64 as such:

ptime from_epoch_ticks(Int64 ticksFromEpoch)
{
    ptime epoch(date(1970, Jan, 1), time_duration(0,0,0));
    ptime time = epoch + boost::posix_time::milliseconds(ticksFromEpoch);

    return time;
}

For some reason, and I can’t figure out why, my dates, hours, etc are all correct, but my minutes are ahead a few minutes from what they should be. Is it because timestamps from the database are in seconds resolution and I’m using milliseconds? How do I fix this?

Applying the following modification as Dan suggested seems to have fixed the problem:

Int64 from_timestamp_t(dtl::timestamp_t& t)
{
    int count = t.fraction * (time_duration::ticks_per_second() % 1000);

    boost::posix_time::ptime pt
        (
        boost::gregorian::date           ( t.year, t.month, t.day ),
        boost::posix_time::time_duration ( t.hour, t.minute, t.second, count )
        );

    ptime epoch(date(1970, Jan, 1), time_duration(0, 0, 0, 0));

    boost::posix_time::time_duration fromEpoch = pt - epoch;

    return fromEpoch.total_milliseconds();
}
  • 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-25T14:39:33+00:00Added an answer on May 25, 2026 at 2:39 pm

    I’m not familiar with SQL Server 2005, but boost posix time has the seconds function if ticksFromEpoch is equivalent to one second.

    ptime time = epoch + boost::posix_time::seconds(ticksFromEpoch);
    

    However, the generic way to handle this is presented in the boost date_time documentation:

    Another way to handle this is to utilize the ticks_per_second() method
    of time_duration to write code that is portable no matter how the
    library is compiled. The general equation for calculating a resolution
    independent count is as follows:

    count*(time_duration_ticks_per_second / count_ticks_per_second)
    

    For example, let’s suppose we want to construct using a count
    that represents tenths of a second. That is, each tick is 0.1 second.

    int number_of_tenths = 5; // create a resolution independent count -- 
                              // divide by 10 since there are
                              //10 tenths in a second.
    int count = number_of_tenths*(time_duration::ticks_per_second()/10);
    time_duration td(1,2,3,count); //01:02:03.5 //no matter the resolution settings
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Server 2005 database that is suffering from lock starvation because
I'm pulling some internationalized text from a MS SQL Server 2005 database. As per
We have SQL Server database setup. We are setting up a replication scenarios where
I have an SQL server database that I am querying and I only want
We have a SQL server database. To manipulate the data non-programmatically, I can use
I have a SQL Server 2005 database and I have 4 GB of text
I have a SQL Server 2000 database with around a couple of hundred tables.
I have a SQL Server 2000 database instance that is rarely updated. I also
We have a SQL Server 2005 database, and currently all our users are connecting
I have a SQL Server 2005 database that I'm trying to access as a

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.