I want to use difftime to count days between today and the day in the future. I don't know how to do the latter. I've tried time_t future = time(???) where '???' would be date chosen by me, but I don't know what to write inside the bracket. I also tried to do separate struct:
1 2 3 4 5 6
struct tm
{
int tm_mday=1;
int tm_mon=4;
int tm_year=116;
}
and then create a one time_t variable from it, but I failed. Is there any easy way?
The easiest way is to first the struct tm structure completely with the date you want to count the time to:
1 2 3 4
struct tm time = {}; //Zero initialize the structure
time.tm_mday = 1;
time.tm_mon = 4;
time.tm_year = 116;
Now you can use the mktime function to create a time_t from this structure. Like so:
time_t future_time = mktime(&time);
Next you can calculate the difference using whatever function you were using. For example, to calculate the number of seconds between the future date and now, you could try:
double difference = difftime(future_time, current_time); //current_time is your current date