Time difference
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Time difference
I usually store my times as YYYYMMDDHHmmSS with hours as 24 hour. This usually works well for telling what date is larger than the other. However what if i wanted to calculate the amount of hours between two dates which span either a month or even a year change like 20150101060000 and 20141231230000. I can easily tell that there is 7 hours difference by looking at it but how would i calculate it
Re: Time difference
Hu.
When in doubt, use the seconds.
Now translating your time stamp into a form LC recognizes will require a couple of lines of code. I would make a function out of it, and keep it somewhere.
Craig Newman
When in doubt, use the seconds.
Now translating your time stamp into a form LC recognizes will require a couple of lines of code. I would make a function out of it, and keep it somewhere.
Craig Newman
Re: Time difference
I was thinking of converting to seconds yet my calculations would be thrown off if i cant account for a leap year.
jan 1 5am = 18000 seconds into the year is an example of converting to seconds however
feb 1 5am would be tricky since id have to know how many days came in january so it would be 31 days + 5 hours = 5202000 seconds thus
march 1 5am is even trickier without knowing if there were 28 days or 29 in february. so spanning a year like my example would have to take the year before into account
jan 1 5am = 18000 seconds into the year is an example of converting to seconds however
feb 1 5am would be tricky since id have to know how many days came in january so it would be 31 days + 5 hours = 5202000 seconds thus
march 1 5am is even trickier without knowing if there were 28 days or 29 in february. so spanning a year like my example would have to take the year before into account
Re: Time difference
The seconds is set to a baseline. They are not tied to any particular year. in a button, try this:
Step through the handler. Unless you need values before the 0th second, which would have to be calculated, this takes into account all that leap stuff. I am not sure if it accounts for leap centuries. Anyone know?
Anyway, if you have two dates, all you need is the absolute value of the difference of their seconds. Then convert that into whatever you like, days, attoSeconds, aeons, whatever.
Craig
Code: Select all
on mouseUp
get the date
convert it to seconds
put 0 into it
convert it to date
answer it
end mouseUp
Anyway, if you have two dates, all you need is the absolute value of the difference of their seconds. Then convert that into whatever you like, days, attoSeconds, aeons, whatever.
Craig
Re: Time difference
but i dont get how you can find how many seconds are between two dates if you dont know how many days the month has.
how many seconds are between 4 seconds to midnight on the 28th of february and 4 seconds past midnight on the 1st of march if you dont first find is there is a whole day inbetween there. To that extent i have devised this little script to find it out
how many seconds are between 4 seconds to midnight on the 28th of february and 4 seconds past midnight on the 1st of march if you dont first find is there is a whole day inbetween there. To that extent i have devised this little script to find it out
Code: Select all
on mouseUp
answer "February has "&checkLeap(2012)&" days in it"
end mouseUp
function checkLeap year
put year&"0229120000" into testLeap
if isNumber(the first char of ourDate("displayfull",testLeap)) then
return 28
else
return 29
end if
end checkLeap
Re: Time difference
never mind i worked it out using what you gave
Re: Time difference
Hi.
Good to hear.
So you now know that LC does a lot of work for you under the hood. Thank goodness.
Craig
Good to hear.
So you now know that LC does a lot of work for you under the hood. Thank goodness.
Craig
Re: Time difference
yeah it does. the converting to seconds and then converting back to date is a huge plus