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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:58:03+00:00 2026-06-18T09:58:03+00:00

How do I compare two timestamps with format yyyy-mm-dd hh-mm-ss to get the total

  • 0

How do I compare two timestamps with format yyyy-mm-dd hh-mm-ss to get the total difference in minutes?

The timestamps are retrieved from MySQL. So far I’ve tried using time_t or even breaking down the whole string to compare but the problem with the latter is it doesnt recognize the difference in days.

thanks in advance!

edit1:
by comparing the timestamps i need to check whether the difference is bigger than x minutes.

like:

timestamp1 = getTimestampFunction1();
timestamp2 = getTimestampFunction2();

difference = timestamp1 - timestamp2; //difference in minutes

if (difference > 60)
{
    do this;
}
else
{
    do that;
}  
  • 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-18T09:58:05+00:00Added an answer on June 18, 2026 at 9:58 am

    This can be done with boost

    #include <boost/date_time/local_time/local_time.hpp>
    
    #include <string>
    using namespace std;
    using namespace boost::local_time;
    using namespace boost::posix_time;
    
    class DateTimeDiff {
        istringstream ss;
        local_time_input_facet* facet;
    public:
        DateTimeDiff(char const * format)
        : facet(new local_time_input_facet(format)) {
            ss.imbue(locale(ss.getloc(), facet));
        }
        double delta_minutes( string t0, string t1 ) {
            local_date_time ldt0(not_a_date_time), ldt1(not_a_date_time);
            ss.str(t0); ss >> ldt0;
            ss.str(t1); ss >> ldt1;
            return time_duration(ldt1 - ldt0).total_seconds() / 60.0;
        }
    };
    
    int main() {
        DateTimeDiff dt("%Y-%m-%d %H-%M-%S");
    
        const string t0 = "2013-01-02 13-14-27",
                     t1 = "2013-02-01 12-56-09";
    
        double diff = dt.delta_minutes(t0,t1);
    
        cout << t0 << " and "
             << t1 << " are "
             << diff << " minutes apart."
             << endl;
    
        cout << diff << " minutes is ";
        if (diff > 60) {
            cout << "more than";
        } else {
            cout << "less than or equal to";
        }
        cout << " one hour." << endl;
    
        return 0;
    }
    

    The output is

    2013-Jan-02 13:14:27 UTC and 2013-Feb-01 12:56:09 UTC are 43181.7 minutes apart.
    43181.7 minutes is more than one hour.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to compare two timestamps and if the difference of that is (-+5minuts)
I would like to compare a difference between two timestamps and a time in
I need to compare two Unix timestamps and I'm having trouble with the math.
Is it correct to compare two values resulting from a call to System.nanoTime() on
I am trying to compare two timestamps to see which one is the latest
I'm trying to compare two millisecond values in Java. One from a calendar, and
I tried to compare date and time of two timeStamp long values as follows.
I got two timestamps in unix format and I need to find a way
I am running through two large log files and I want to compare timestamps.
I want to find the precent change in two values from a mysql database.

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.