add the specified number of days to current date
-
Hi! i use localtime function to get current time, in "tm struct". how do i get a new "tm struct" that adds the specified number of days to the value of this instance. this is similar with DateTime::AddDays, but i don't use any MFC Class.
time_t t;
struct tm * tt;
char buffer[50];
time(&t);
tt = localtime(&t);
int dayOfWeek = tt->tm_wday; // days since sunday
tt->tm_mday -= dayOfWeek;in this code there is a bug. if tt->tm_mday < dayOfWeek then ??? please help me.
Zo.Naderi-Iran
-
Hi! i use localtime function to get current time, in "tm struct". how do i get a new "tm struct" that adds the specified number of days to the value of this instance. this is similar with DateTime::AddDays, but i don't use any MFC Class.
time_t t;
struct tm * tt;
char buffer[50];
time(&t);
tt = localtime(&t);
int dayOfWeek = tt->tm_wday; // days since sunday
tt->tm_mday -= dayOfWeek;in this code there is a bug. if tt->tm_mday < dayOfWeek then ??? please help me.
Zo.Naderi-Iran
Why don't you add the proper number of seconds (
1
day is86400
secs) directly to thetime_t
variable? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Why don't you add the proper number of seconds (
1
day is86400
secs) directly to thetime_t
variable? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Another answer is To get system date: COleDateTime curDateTime; curDateTime = COleDateTime::GetCurrentTime(); COleDateTimeSpan represents a relative time, a time span. COleDateTimeSpan daySpan(25,0,0,0); 25 represents 25 days span. Next three zeros – hours, minutes, and seconds. Wanna get the date, 25 days from current date, add daySpan with curDateTime: COleDateTime comDateTime; comDateTime = curDateTime + daySpan; Also see CTime and CTimeSpan