LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Starting day of month, month length (http://www.linuxquestions.org/questions/programming-9/starting-day-of-month-month-length-153114/)

chrisk5527 03-03-2004 03:39 PM

Starting day of month, month length
 
Does anyone have an algorithm that shows how to calculate the first day of the month, and the number of days? How would I know if a month started on Wednesday?

haobaba1 03-03-2004 04:52 PM

Re: Starting day of month, month length
 
Quote:

Originally posted by chrisk5527
Does anyone have an algorithm that shows how to calculate the first day of the month, and the number of days? How would I know if a month started on Wednesday?
I don't know what language you are using but Java's calendar class can do all that and more.

jim mcnamara 03-03-2004 05:03 PM

Code:

#include <time.h>                                                     
#include <stdlib.h>
/* parameters 1 - month as a number from 1 - 12  2 - year (from 1900 on) */
/* this does no error checking */
int main(int argc, char *argv[]){
      int year=atoi(argv[2]);
      int month=atoi(argv[1]);
      char tmp[64]={'\0'};
      struct tm  my_tm;
      time_t timer;
   
      my_tm.tm_year=year-1900;
      my_tm.tm_isdst=0;
      my_tm.tm_sec=1;
      my_tm.tm_min=0;
      my_tm.tm_hour=0;
      my_tm.tm_mon=month;
      timer=mktime(&my_tm);
      strftime(tmp,60,"%A is the first day of %B, %Y",&my_tm);
      printf("%s \n",tmp);
           
}   

/*
    struct tm {
        int tm_sec;    /o second (0-61, allows for leap seconds) o/
        int tm_min;    /o minute (0-59) o/
        int tm_hour;    /o hour (0-23) o/
        int tm_mday;    /o day of the month (1-31) o/
        int tm_mon;    /o month (0-11) o/
        int tm_year;    /o years since 1900 o/
        int tm_wday;    /o day of the week (0-6) o/
        int tm_yday;    /o day of the year (0-365) o/
        int tm_isdst;  /o non-0 if daylight savings time is in effect o/
    };
 
 
 
*/



All times are GMT -5. The time now is 04:42 AM.