I'll look at that. I did tried tm once but if I remember I got 2 for example
rather than March.
Maybe strftime was what I missed.
In your prior post you cautioned about rounding. Thanks for that. I got 0
when I expected 1 until I remember your caution.
thanks
> I'll look at that. I did tried tm once but if I remember I got 2 for
> example rather than March.
> Maybe strftime was what I missed.
>
> In your prior post you cautioned about rounding. Thanks for that. I got 0
> when I expected 1 until I remember your caution.
Wasn't my post actually, but...
Define what you mean by "number of days since then". If the saved time is
11:59 PM on Feb 1, and current system time is 12:03 AM on Feb 2, the delay
is only 4 minutes, but midnight passed... so do you count that as a day?
Rounding won't really help you there.
If you mean calendar days, then you may want to convert your time_t to a tm
using localtime, zero the hour/minute/second fields, use mkgmtime to go back
to time_t, then difftime and divide by (24*60*60). In that way you will
count days elapsed since the beginning of the day in which the saved time
occurred.
> thanks
>
[quoted text clipped - 23 lines]
>>>>> Failing that I'd like to display the date (only the date) that
>>>>> corresponds to the saved time_t variable.
Carl Daniel [VC++ MVP] - 17 Jan 2007 15:28 GMT
> If you mean calendar days, then you may want to convert your time_t
> to a tm using localtime, zero the hour/minute/second fields, use
> mkgmtime to go back to time_t, then difftime and divide by
> (24*60*60). In that way you will count days elapsed since the
> beginning of the day in which the saved time occurred.
or just do the division first, then the subtraction:
int num_days = (end_time_t / 86400) - (start_time_t/86400);
Will always give the difference in day number between two time_t values. If
you want the "rollover" from one day to the next to be at a time other than
midnight (e.g. to counts days in a different timezone than the one
represented in your time_t), then just subtract the appropriate number of
hours*3600 from each time_t before dividing.
-cd
Frank - 17 Jan 2007 16:54 GMT
Thanks for all the insight.
I'm showing the days since and also the prior date.
I got two extra characters displayed so I added the last line shown below.
Can you tell me what is going on?
Thanks again
struct tm pasttime;
localtime_s( &pasttime, &OldTime );
strftime( szTmpStr, 100, "%A %B %d, %Y\n", &pasttime );
szTmpStr[lstrlen(szTmpStr)-1] = 0;
Ben Voigt - 17 Jan 2007 17:13 GMT
> Thanks for all the insight.
>
> I'm showing the days since and also the prior date.
>
> I got two extra characters displayed so I added the last line shown below.
That extra line removes the newline character you have in the format string.
Perhaps it's also going through newline translation and becoming a CR/LF
pair.
Try just removing the "\n" from the format string.
> Can you tell me what is going on?
>
[quoted text clipped - 7 lines]
>
> szTmpStr[lstrlen(szTmpStr)-1] = 0;
Frank - 17 Jan 2007 17:34 GMT
ouch!
thanks
>> Thanks for all the insight.
>>
[quoted text clipped - 20 lines]
>>
>> szTmpStr[lstrlen(szTmpStr)-1] = 0;