Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

How to find the difference between two given dates, and difference should be in number of days.

Like: older Date is : 11-Jan-2012 18:31:55
new Date is : system current date.

with above dates, how to find the difference between these two dates in number of days.

can anyone give me some idea regarding this.

Thank you in Advance.
Posted

The idea is to convert both dates into a serial day number and then simply subtracting both numbers from each other.

One way of doing that is to use the C/C++ runtime function "time" to convert you dates into seconds since midnight 1.1.1970. Then, subtract both results from each other and you have the difference in seconds. Divide that by 86400 and you have the difference in days.
 
Share this answer
 
Comments
Kumar 09 12-Mar-13 3:13am    
any example
Try this:
C++
#include <iostream>
#include "boost/date_time/gregorian/gregorian.hpp"

namespace bdt = boost::gregorian;

int main(void)
{
    bdt::date today(bdt::date(2010, bdt::Jun, 13));
    bdt::date electionDay(bdt::date(2010, bdt::Nov, 2));
    bdt::date_period range(today, electionDay);


    std::cout << "Days between " << today
              << " and " << electionDay
              << " is " << range.length() << std::endl;

    return 0;
}

Found it here[^]
 
Share this answer
 
Comments
[no name] 12-Mar-13 3:17am    
5!
Prasad_Kulkarni 12-Mar-13 3:25am    
Thank you Pranit!
J.Surjith Kumar 16-Mar-13 8:20am    
my 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900