[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LOCALE ERROR - RE: how to compare 2 dates - NOW WITH TIME
- From: KHMan <keinhong@...>
- Date: Sat, 09 May 2009 02:45:29 +0800
Diego - Red Baires wrote:
Hi guys, i still cannot apply the concept that Kein recommends.
Pls analize this results:
^^^^^^^
analyze
----------
myHour = os.time( { year="2008", month="01", day="01", hour="00",
min="00" })
ts = math.fmod(myHour, 86400)
print (myHour .." - ".. ts)
myHour = os.time( { year="2009", month="01", day="00", hour="00",
min="00" })
ts = math.fmod(myHour, 86400)
print (myHour .." - ".. ts)
----------
output:
1199152800 - 7200
1230688800 - 7200
Heh, there is no day 00 :-)
The 7200 is the difference in time zone versus UTC, because the
Unix epoch is 00:00:00 UTC on January 1, 1970. Looks like Spain.
What are you doing with fmod? You can use myHour % 86400.
But why are you using fmod? Is your date a local date or a UTC
date? If it's local date, you count your hours with respect to
your midnight reference of the same day. I've already shown that.
If your application is international, then you also need to take
into consideration your time zone.
it continues to return "7200" if i change the year (it is what we
expect) but it returns
different values to different months values. see this
----------
myHour = os.time( { year="2008", month="01", day="01", hour="00",
min="00" })
ts = math.fmod(myHour, 86400)
print (myHour .." - ".. ts)
myHour = os.time( { year="2009", month="07", day="00", hour="00",
min="00" })
ts = math.fmod(myHour, 86400)
print (myHour .." - ".. ts)
----------
output:
199152800 - 7200
1246330800 - 10800
The only thing I can think of that changes it would be Daylight
Savings Time (DST). On my machine, there is no difference in the
ts result, meaning that on both dates, the times have the same
hour difference with respect to UTC.
is it because of the locale ?
do you have any example to set UTC locale ? (i coudnt find an example)
If you have DST, and you specify dates in local time, then the
calculations will be more complex. I'll leave the implementation
to you. :-)
--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia
- References:
- rare sorting on a table, Diego - Red Baires
- Re: rare sorting on a table, Wim Couwenberg
- Re: rare sorting on a table, Doug Rogers
- how to compare 2 dates, Diego - Red Baires
- Re: how to compare 2 dates, Petite Abeille
- RE: how to compare 2 dates - NOW WITH TIME, Diego - Red Baires
- Re: how to compare 2 dates - NOW WITH TIME, KHMan
- RE: how to compare 2 dates - NOW WITH TIME, Diego - Red Baires
- Re: how to compare 2 dates - NOW WITH TIME, KHMan
- LOCALE ERROR - RE: how to compare 2 dates - NOW WITH TIME, Diego - Red Baires