To find the day (number) for a given date, I wrote below code using <ctime>
:
tm time {ANY_SECOND, ANY_MINUTE, ANY_HOUR, 21, 7, 2015 - 1900};
mktime(&time); // today's date
PRINT(time.tm_wday); // prints 5 instead of 2 for Tuesday
According to the documentation, tm_wday
can hold value among [0-6]
, where 0 is Sunday. Hence for Tuesday (today), it should print 2; but it prints 5.
Actually tm_wday
gives consistent results, but with a difference of 3 days.
What is wrong here?