Is there a time function or class that will allow me to find the starting and ending day of the week for any month (example: january 2000 starts on a saturday)?
Is there a time function or class that will allow me to find the starting and ending day of the week for any month (example: january 2000 starts on a saturday)?
Well... there is a variable in time.h called tm_wday. Sunday = 0, Saturday = 6.
Ummm... I don't know how to get the structure loaded with the date-of-interest... So, I guess you'll have to look that up... Or, wait for someone else to answer.
Code:time_t typedef a-type time_t; // The type is the arithmetic type a-type of an object that you // declare to hold the value returned by time. The value // represents calendar time. tm struct tm { int tm_sec; seconds after the minute (from 0) int tm_min; minutes after the hour (from 0) int tm_hour; hour of the day (from 0) int tm_mday; day of the month (from 1) int tm_mon; month of the year (from 0) int tm_year; years since 1900 (from 0) int tm_wday; days since Sunday (from 0) int tm_yday; day of the year (from 0) int tm_isdst; Daylight Saving Time flag };
Last edited by DougDbug; 09-05-2003 at 12:24 PM.
Try this to find the first day. Once you have that it's a simple matter to get the last day:
Code:int first_day_of_month ( int year, int month ) { struct tm t = { 0 }; struct tm *tp; time_t now; t.tm_mday = 1; t.tm_mon = month-1; t.tm_year = year-1900; now = mktime(&t); tp = localtime(&now); return tp->tm_wday; }
My best code is written with the delete key.