Quote:
Originally Posted by jkappers
Well, what's really got me thrown off at this point is that I'm used to new languages (for this example I'll use Javascript) where using dates is as easy as creating a Date() object and using methods like getMonths() to get the months integer value.
Yup.. C is pretty nitty gritty.
Quote:
Originally Posted by jkappers
Here, the only way I can think to do this would be to create a string and somehow grab the integert values out of the date string. I assume there are some functions in <string.h> that could help me achieve this.
No need.. just use your tm struct like you do above and pass two of that variable to a function that does the work. You allready set year, month, day to specific values.. getting them back is just as easy. If you need the year out of your tm struct just do:
int year = timeinfo->tm_year; <--- bear in mind the year is minus 1900.
Stop thinking about it as an object and call a function to do the work.
int Determine_Greater_Than_5_Days(struct tm *Date1, struct tm *Date2)
{
return !Determine_Less_Than_5_Days(Date1, Date2);
}
int Determine_Greater_Than_5_Days(struct tm *Date1, struct tm *Date2)
{
int Temp_Year = timeinfo -> tm_year; // etc
// Branch based on Year/Month/Day for the two Dates in the style I wrote up above. Make sure to keep functioning out each branch so its readable.
}