LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 03-03-2004, 02:39 PM   #1
chrisk5527
Member
 
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289

Rep: Reputation: 30
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?
 
Old 03-03-2004, 03:52 PM   #2
haobaba1
Member
 
Registered: Jul 2003
Location: VA Tech
Distribution: Mandrake 9.1
Posts: 73

Rep: Reputation: 15
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.
 
Old 03-03-2004, 04:03 PM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
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/
     };
  
  
  
*/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
transform month number to month name in php ALInux Programming 1 11-09-2005 10:45 AM
Multicount in PHP , displays visits on current day, week, month, year and total visit xbaez Programming 1 04-24-2005 02:50 AM
cron last day of every month lobo78 Linux - General 2 03-03-2004 08:41 PM
back after a month nakkaya General 3 06-22-2003 11:22 PM
ip traffic mb/month thorwil Linux - Networking 2 04-23-2003 08:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration