0

I have a file, 'date-list.txt' which has date in it. For example , 20 May 2012 .

Now I want to compare this date with current system date and show the difference in days .

How can i compare dates and shows difference in days in C++.?

Im really a c++ beginner . So , if possible , please show and guide me with codes . Thanks in advanced .

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by subith86
0

Boost library is one option. But given that you are a beginner, and you want to go the hard way by using less complex C++ concepts, then think and note down how you will do this task if you were asked to do it manually.

  1. take the given day, month, year. (It can be stored in a structure, if you have learned it already)
  2. take system day, month, year. (structure as above)
  3. Modify given date by adding x to the given day so that it matches system day. Leap years to be taken into account.
  4. Modify given date by adding y to the given month so that it matches system month. Count number of days in this gap (30+31+31+30+31....). Lets call it y_days. Leap years to be taken into account.
  5. add z to the given year so that it matches system year. Count the number of days in this gap. Lets call it z_days. z_days = z * 365.
  6. count the number of leap years between 2 years. let it be called ly.
  7. Number of days = x + y_days + z_days + ly

Now go ahead and implement :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.