Thread: time functions

  1. #1
    Registered User
    Join Date
    Sep 2003

    time functions

    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)?

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001

    Lightbulb tm_wday

    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.

    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.
    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.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Try this to find the first day. Once you have that it's a simple matter to get the last day:
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 04:44 AM
  2. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  3. The space time continueimnms mm... (rant)
    By Jeremy G in forum A Brief History of
    Replies: 32
    Last Post: 06-27-2004, 01:21 PM
  4. I apologize. Good bye.
    By doubleanti in forum A Brief History of
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM
  5. help with functions (first time)
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 03-06-2002, 09:37 PM