Hi there,
The programe below outputs the difference between two dates, i want to edit it so the 1st date is always today's date. Would i need to use the time function or rawtime. I am struggling to integrate it into the format of this programme. Could anyone point me in the right direction?
Code:
#include <stdio.h> //
#include <time.h> // Include C time functions in header
int daysto(struct tm *before, struct tm *after) // Grouping code for daysto calculation
{
time_t first = mktime(before), second = mktime(after); // Declaring time_t
if ( first != (time_t)-1 && second != (time_t)-1 ) // If first and second date is not equal return the difference
{
return difftime(second, first) / (60 * 60 * 24); // Converting time into days. difftime function for first and second date
}
return-1 ; //Anything non zero is true
}
int main(void) // Function takes no arguements
{
struct tm one = {0}, two = {0};
one.tm_year = 109; // mktime function caclculates from the year 1900
one.tm_mon = 3 - 1; // Month input. Months start a 0 so -1
one.tm_mday = 24; // Day of the month input
two.tm_year = 109; // mktime function calculates from the year 1900
two.tm_mon = 4 - 1; // Month input. Months start a 0 so -1
two.tm_mday = 3; // Day of the month input
printf("Number of days till deadline = %d\n", daysto(&one,&two)); // Printing the result of the calculation
return 0;
}
Thanks in advance