Another mention question from library territory. If this is your first visit, one of the things I do here on the blog is to answer questions that I get at work while on the reference desk.
Today the question was, casually put, “How many seconds in one day?”
Let’s do some math.
60 minutes x 60 minutes = 3600 seconds in 1 hour.
3600 seconds x 24 hours = 86,400 seconds in one day.
If like me, mathematics doesn’t come naturally to you and you are looking for better, I highly recommend the math videos at the Khan Academy.
Now that you know how many seconds in have been in a day, use your powers for good!
Sixty, and no longer in it.
Sixty for sun and shower.
Twenty-four for play and work.
Seven both to listen to and speak.
Four, as the swift moon runn’th.
Twelve, the almanac makes clear.
One hundred, says the sage.
Nobody understands the thought.
What we needed to do was to calculate the number of days between two specified dates.
Sounds simple enough, even with all the awkward Date interface you can certainly work out that it should be possible to find a number of milliseconds between two dates and turn that into a variety of days.
The code looked something like this:
var firstDate = new Date(2012,9,12);
var lastDate = new Date(2012,9,20);
var difference = lastDate.getTime() – firstDate.getTime();
var dayInMilliseconds = 1000 * 60 * 60 * 24;
var days = difference / dayInMilliseconds;
It’s all pretty straight forward before you actually begin testing the code and happen to enter marginally different dates.
Only occasionally it is not. This just happened to have been composed in the UK where we observe DST, which finishes on the 28th
var firstDate = new Date(2012,9,27);var lastDate = new Date(2012,9,29); var difference = lastDate.getTime() – firstDate.getTime(lastDate.getTimezoneOffset() – firstDate.getTimezoneOffset()) * 60 * 1000;var dayInMilliseconds = 1000 * 60 * 60 * 24; var days = difference / dayInMilliseconds;
It is probably a slightly better solution. That’s until we find there’s something called a leap second.
There is a simple formula used if you want to convert second to days. We divide the number of seconds by 86,400 to get the number of days.
Days = seconds ÷86,400
For example, Convert 98,400 seconds to days
If 1 day = 86,400 seconds
? Days = 98,400 seconds?
= 98,400 / 86,400
= 1.138889 days
You can also use the Seconds to Day converter as it gives the corresponding values in days when converting from seconds. This conversion calculator will be useful when you have large values in seconds that are to be converted to days. If you want to determine how many seconds in a day, we multiply the number of seconds in one hour by the number of hours in one day.