Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Algorithms
Expertise: Beginner
Mar 25, 1999

Displaying a date

Question:
I have a date stored as an integer -- days from 1/1/1900. iis there an algorithm out there to display the day, month, and year? Or is there an easy way to do this? Month seems to be the real problem because they each have a different number of days.

Answer:
Well, I'm not going to write this for you for the simple reason that the leg work and testing would be beyond the scope of this forum. But I have done stuff like this in the past and can give you some tips to get started.

First, I would divide the number by 365 to get the year and determine the month and day from what remains.

I think I would create an array of integers that hold the number of days in the month that corresponds to each item in the array. This would allow you to perform very quick look ups to determine which month; what remained would, of course, indicate the day.

Unfortunately, it is even a little more complicated than that since leap years do not contain 365 days, but I hope this will get you started.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date