943,917 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3649
  • C RSS
Mar 21st, 2008
0

gregorian calendar, help

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
modaslam is offline Offline
11 posts
since Mar 2008
Mar 21st, 2008
0

Re: gregorian calendar, help

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 21st, 2008
0

Re: gregorian calendar, help

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.
Reputation Points: 62
Solved Threads: 10
Junior Poster
jim mcnamara is offline Offline
179 posts
since May 2004
Mar 22nd, 2008
0

Re: gregorian calendar, help

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
modaslam is offline Offline
11 posts
since Mar 2008
Mar 23rd, 2008
0

Re: gregorian calendar, help

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jonnelgrande is offline Offline
6 posts
since Dec 2007
Mar 24th, 2008
0

Re: gregorian calendar, help

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
modaslam is offline Offline
11 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Combinations of a string using Recursion(Modified Version)
Next Thread in C Forum Timeline: header file confusion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC