Hi
moodle stores date fields in the big int format, can anyone suggest how to find the difference between two date values
4 Aug 2009 is stored as 1249340400
5 Aug 2009 is stored as 1249426800
is there any date difference function difined somewhere?
Thanks,
Nitin
Nitin,
Do you want a formula to calculate the difference between two Unix timestamp dates ... in days? in days and hours ? etc. Please be more specific.
Joseph
Do you want a formula to calculate the difference between two Unix timestamp dates ... in days? in days and hours ? etc. Please be more specific.
Joseph
yes please.
i need to calculate difference in days
Thanks,
Nitin
i need to calculate difference in days
Thanks,
Nitin
You could use/adapt the function by Charles W. Reace, Jr. here.
If you have the start and the end dates in unix timestamp format, then instead of
$start = strtotime('2009-08-4 00:00:00');
$end = strtotime('2009-08-5 00:00:00');
just put the unix timestamps:
$start = strtotime('1249340400');
$end = strtotime('1249426800');
Please note that you may have to add one second to the end date. And if you are only interested in days, you'll have to modify the timeDiff() function accordingly.
Joseph
Many Thanks!
Given that a UNIX timestamp is just a number of seconds, you can just subtract one time from the other, divide by (24*60*60), and apply appropriate rounding.
Hubert, could you please tell us how you would "apply appropriate rounding" to a number of UNIX timestamp seconds?
TIA
Joseph
TIA
Joseph
When you divide the number of seconds by 24*60*60, you may get a fractional result. Depending on how you want to treat a fraction of a day, you may want to use, e.g. the PHP round, ceil, or floor functions. Or you could do something more complicated if, say, you wanted 23 hours to be counted as a full day, but 22 hours, 59 minutes, and 59 seconds as not a full day.