954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

gregorian calendar, help

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

long xx;
int yy,dd,m;
xx = 365 + yy +dd+31*(m-1)
if(m<3)
xx= xx+((yy-1)/4)-(0.75*(yy-1)/100 + 1);
else
xx = xx-(0.4*mm+2.3)+(yy/4)-(0.75*(yy/100)+1));



Thankyou

modaslam
Newbie Poster
11 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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_book/chapter9/date_and_time.html

jim mcnamara
Junior Poster
180 posts since May 2004
Reputation Points: 62
Solved Threads: 10
 

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_book/chapter9/date_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.

modaslam
Newbie Poster
11 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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]email snipped[/email]

jonnelgrande
Newbie Poster
6 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

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]email snipped[/email]


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

modaslam
Newbie Poster
11 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You