« Code for detecting if it's BST | Main | Mental BST events SQL with cluster tags included »

September 24, 2009

Is this date during BST?


-- Check that the event_start_date is in British Summer Time

and ('1970-01-01 01:00:00 GMT'::timestamp + ((e.event_start_date::bigint)::text)::interval between

-- Get the last Sunday in March

date_trunc('month', (extract('year' from now()::timestamp)::text||'-03-01 00:00:00 GMT'::text)::timestamp + 
'1 month'::interval) - '1 day'::interval + 
(((1 - 7 - to_char(date_trunc('month', (extract('year' 
from now()::timestamp)::text||'-03-01 00:00:00 GMT'::text)::timestamp + '1 month'::interval) 
- '1 day'::interval,'D')::int) %7)||' days')::interval

and

-- Get the last Sunday in October

date_trunc('month', (extract('year' from now()::timestamp)::text||'-10-01 00:00:00 GMT'::text)::timestamp + 
'1 month'::interval) - '1 day'::interval + 
(((1 - 7 - to_char(date_trunc('month', (extract('year' 
from now()::timestamp)::text||'-10-01 00:00:00 GMT'::text)::timestamp + '1 month'::interval) 
- '1 day'::interval,'D')::int) %7)||' days')::interval )

-- The 1 specifies Sunday

 

Posted by pj at September 24, 2009 11:23 PM

Comments