gregorian calendar, help

Reply

Join Date: Mar 2008
Posts: 11
Reputation: modaslam is an unknown quantity at this point 
Solved Threads: 0
modaslam modaslam is offline Offline
Newbie Poster

gregorian calendar, help

 
0
  #1
Mar 21st, 2008
Hello Geeks,
I am working on a program for date,month calculation.
I found this code used to convert to Gregorian format for calculation.
It would be great full for me if anybody can explain this ... like 0.75 yy/4 .4*mm what are these constants why m-1, yy-1 etc..
  1. long xx;
  2. int yy,dd,m;
  3. xx = 365 + yy +dd+31*(m-1)
  4. if(m<3)
  5. xx= xx+((yy-1)/4)-(0.75*(yy-1)/100 + 1);
  6. else
  7. xx = xx-(0.4*mm+2.3)+(yy/4)-(0.75*(yy/100)+1));
Thankyou
Last edited by modaslam; Mar 21st, 2008 at 7:58 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: gregorian calendar, help

 
0
  #2
Mar 21st, 2008
>what are these constants
Why don't you ask the person who created the formula?

>why m-1, yy-1 etc..
I imagine because m and yy are 1 based, and the formula works better with values that are 0 based.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 178
Reputation: jim mcnamara is on a distinguished road 
Solved Threads: 10
jim mcnamara jim mcnamara is offline Offline
Junior Poster

Re: gregorian calendar, help

 
0
  #3
Mar 21st, 2008
I have no idea why the original coder wrote that stuff, except it appears the s/he did not know about the standard C library date/time functions.

date arithmetic is best done with that library - convert a date/time to a struct tm, convert the struct tm to epoch seconds. Do the same thing with another time or date. Now you can add subtract or whatever - like what date & time was it 48 days ago? You don't have to worry about leap years, for example.

Work backwards to get a new date.

The functions you need are
gmtime or localtime
mktime
strftime

You also have to learn what goes into struct tm, so you can build one if your system does not have strptime.
here is some help:
http://publications.gbdirect.co.uk/c..._and_time.html
Last edited by jim mcnamara; Mar 21st, 2008 at 2:27 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: modaslam is an unknown quantity at this point 
Solved Threads: 0
modaslam modaslam is offline Offline
Newbie Poster

Re: gregorian calendar, help

 
0
  #4
Mar 22nd, 2008
Originally Posted by jim mcnamara View Post
I have no idea why the original coder wrote that stuff, except it appears the s/he did not know about the standard C library date/time functions.

date arithmetic is best done with that library - convert a date/time to a struct tm, convert the struct tm to epoch seconds. Do the same thing with another time or date. Now you can add subtract or whatever - like what date & time was it 48 days ago? You don't have to worry about leap years, for example.

Work backwards to get a new date.

The functions you need are
gmtime or localtime
mktime
strftime

You also have to learn what goes into struct tm, so you can build one if your system does not have strptime.
here is some help:
http://publications.gbdirect.co.uk/c..._and_time.html
Its not like that. we are not supposed to use any library functions.. for finding the date.
Actually the program is to find the days elapsed between to given days.

The code snippet i have given is to convert the normal date to Gregorian type.

what they have explained is first they take two days and convert to Gregorian type.
and subtract second from first. so that they can get the difference in days elapsed

To convert a normal date to Gregorian type they used this function.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 6
Reputation: jonnelgrande is an unknown quantity at this point 
Solved Threads: 0
jonnelgrande jonnelgrande is offline Offline
Newbie Poster

Re: gregorian calendar, help

 
0
  #5
Mar 23rd, 2008
I am wondering if we can build a calendar in C language...

...as in Gregorian Calendar format and design

Is there any code that could help me to print or to display a Gregorian Calendar???

pls. reply... thanks... God bless...


my yahoo email add is: email snipped
Last edited by WolfPack; Mar 24th, 2008 at 12:16 pm. Reason: Removed email address per forum rules.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: modaslam is an unknown quantity at this point 
Solved Threads: 0
modaslam modaslam is offline Offline
Newbie Poster

Re: gregorian calendar, help

 
0
  #6
Mar 24th, 2008
Originally Posted by jonnelgrande View Post
I am wondering if we can build a calendar in C language...

...as in Gregorian Calendar format and design

Is there any code that could help me to print or to display a Gregorian Calendar???

pls. reply... thanks... God bless...


my yahoo email add is: email snipped
The code i have given in this thread accept a normal date of format dd mm yy format and convert to Gregorian format well basically the this snippet is function used to convert the date.
okay
Last edited by WolfPack; Mar 24th, 2008 at 12:17 pm. Reason: Removed email from quoted message.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC