11 Sie 2010

Operacje na datach przy wykorzystaniu date_trunc

select czas, date_trunc('day', czas)+'15:59:12' as czas2 from czas limit 1;
UPDATE czas set czas = date_trunc('day', czas)+'15:59:12' WHERE wt_id = 3850;

"2008-11-07 15:58:37";"2008-11-07 15:59:12"

select
  czas, date_trunc('day', czas), date_trunc('day', timestamp '2010-08-11')
from
  czas_t
where
  date_trunc('day', czas) = date_trunc('day', timestamp '2010-08-11')

"2010-08-11 07:37:46";"2010-08-11 00:00:00";"2010-08-11 00:00:00"
"2010-08-11 07:40:49";"2010-08-11 00:00:00";"2010-08-11 00:00:00"
"2010-08-11 08:04:42";"2010-08-11 00:00:00";"2010-08-11 00:00:00"
"2010-08-11 09:12:32";"2010-08-11 00:00:00";"2010-08-11 00:00:00"
"2010-08-11 08:55:52";"2010-08-11 00:00:00";"2010-08-11 00:00:00"
"2010-08-11 15:59:12";"2010-08-11 00:00:00";"2010-08-11 00:00:00"

12 Mar 2010

Zapytanie do bazy z wykorzystaniem funkcji NOW()

select * from table where t_add_date < NOW()-'5 MONTH'::interval
select * from table where t_add_date < NOW()+'5 MONTH'::interval
select * from table where t_add_date < NOW()-'1 DAY'::interval
select * from table where t_add_date < NOW()-'2 DAYS'::interval
select * from table where t_add_date < NOW()-'1 DAY'::interval
select * from table where t_add_date < NOW()-'5 MINUTES'::interval
select * from table where t_add_date < NOW()-'3 HOURS'::interval
18 Wrz 2009

Obliczanie różnicy czasu

echo (strtotime("2009-09-14 15:55:00")-strtotime("2009-09-14 11:00:02"));
$hour_ts = 3600;
$day_ts = 86400;
$modif_ts = strtotime("-10 day");
$modif_ts = strtotime("-4 hours");
$modif = strtotime("2009-09-14 15:55:00");
$modif_ts = strtotime($modif);
$now_ts = time()+1;
$d_ts = $now_ts-$modif_ts;
echo $d_ts .'';