We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,716 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Comparing and sorting of Dates.

Good day.
I am busy writing a small console program and need help with the following:

- I need to be able to allow the user to enter a start date and end date and display data with dates which falls wihin this range.

- Once I have this data, I need to be able to sort the data by date.

I will be ever grateful if anyone can give me and example of how to do this as I am new to c++.
Thanks in advance.

Regards,

2
Contributors
1
Reply
8 Hours
Discussion Span
8 Years Ago
Last Updated
3
Views
cwobie
Newbie Poster
1 post since Sep 2004
Reputation Points: 11
Solved Threads: 0
Skill Endorsements: 0

You may want to use a struct tm to hold integer values for the month, day, and year that the user enters. But keep in mind that this structure normally has the month from 0-11 and the year is a two-digit value based on the year 1900 (that is, 2004 is represented with the value 104). Using the struct tm properly lets you use other time-manipulation functions.

You could also make your own struct and keep dates "normal", or just use the struct tm with "normal" values. Either way, for the sorting would then recommend qsort (assuming C). What you would need to do is make your own comparison function.

Well, I see I'm already assuming too much about how you are defining records, the language you are using, and other such things. Do you have a start that you can show?

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Skill Endorsements: 39

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0598 seconds using 2.73MB