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 .

i would look at using the Boost date time library if i were you.

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.