time functions

This is a discussion on time functions within the C++ Programming forums, part of the General Programming Boards category; Is there a time function or class that will allow me to find the starting and ending day of the ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    1

    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
    Posts
    1,398

    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.

    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 01:24 PM.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    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.

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 Cprogramming.com
    Replies: 32
    Last Post: 06-27-2004, 02:21 PM
  4. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 07:51 PM
  5. help with functions (first time)
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 03-06-2002, 09:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21