• Subject: Re: LOCALE ERROR - RE: how to compare 2 dates - NOW WITH TIME
• From: KHMan <keinhong@...>
• Date: Sat, 09 May 2009 18:09:56 +0800

```Petite Abeille wrote:
```
```On May 8, 2009, at 9:30 PM, KHMan wrote:
```
Sorry, it is probably not Spain, I Googled too quickly. I'll stop making wild guesses. :-)
```
```
The OP's IP is reported as 201.235.35.174, which looks like Buenos Aires, Argentina, so UTC/GMT -3 hours perhaps.
```
```
That's a better guess. Making wild guesses quickly without engaging the brain was dumb. :-)
```
```
Here is a simple implementation for Diego, perhaps it's closer to his requirements. It can be shorter, but is laid out for clarity. Only does local time, however.
```
-- start_date: day on which campaign starts (table)
-- end_date: day on which campaign ends (table)
--           (inclusive, assume the whole of end_date
--            is still a campaign day)
--
-- start_time: time on which campaign starts (table)
-- end_time: time on which campaign ends (table)
--           (exclusive, last valid time is 1 second
--            before end_time)
--
-- * Assume for dates, year,month,day are valid
-- * Assume for times, hour,min are valid
--
-- (1) test if current date is in campaign date range
--     and if true, then,
-- (2) test if current time is in campaign time range
--     and if true,then,
-- (3) run something

-- current date/time
local today = os.date("*t")
local t_today = os.time()

-- DEBUG some values for testing only
local start_date, end_date = today, today
local start_time = {hour=17,min=0}
local end_time = {hour=19,min=0}

-- dates to compare (time made up as date at midnight)
local d_start =
os.time{year = start_date.year,
month = start_date.month,
day = start_date.day,
hour = 0, min = 0}
local d_end =
os.time{year = end_date.year,
month = end_date.month,
day = end_date.day,
hour = 0, min = 0}
local d_today =
os.time{year = today.year,
month = today.month,
day = today.day,
hour = 0, min = 0}

-- check if today is a campaign date
if d_today >= d_start and d_today <= d_end then
local t_start =
os.time{year = today.year,
month = today.month,
day = today.day,
hour = start_time.hour,
min = start_time.min}
local t_end =
os.time{year = today.year,
month = today.month,
day = today.day,
hour = end_time.hour,
min = end_time.min}
-- check if now is within campaign time
if t_today >= t_start and t_today < t_end then
print("Yep")
else
print("Nope")
end
end

Something like that.

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

```