devxlogo

Displaying a date

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.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist