Visit Jeremy's Blog.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org Starting day of month, month length
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 03-03-2004, 02:39 PM #1 chrisk5527 Member   Registered: Oct 2002 Location: Michigan Distribution: Slackware Linux 10.0 Posts: 289 Rep: 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?
03-03-2004, 03:52 PM   #2
haobaba1
Member

Registered: Jul 2003
Location: VA Tech
Distribution: Mandrake 9.1
Posts: 73

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

 03-03-2004, 04:03 PM #3 jim mcnamara Member   Registered: May 2002 Posts: 964 Rep: Code: ```#include #include /* 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/ }; */```

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post ALInux Programming 1 11-09-2005 10:45 AM xbaez Programming 1 04-24-2005 02:50 AM lobo78 Linux - General 2 03-03-2004 08:41 PM nakkaya General 3 06-22-2003 11:22 PM thorwil Linux - Networking 2 04-23-2003 08:33 AM

All times are GMT -5. The time now is 06:30 AM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -