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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date