看板 PHP 關於我們 聯絡資訊
各位大大!!我想請問一個PHP問題\ insert into A (Id,DateTime)valuse("",NOW()); 資料表 A Id | DateTime 1 2012-07-21 2 2012-07-25 我想取出欄位DateTime並作時間計算 $query =$this->db->query("select DateTime from A where Id='1'"); $row = $query->row(); 因此 $row->DateTime 就會等於 2012-07-21 我想問的是我要怎麼將 $row->DateTime 做加減運算??? EX: 2012-07-21 我想加 7 天 要怎麼做? $row->DateTime + 7 ?? -- Aman ia vida 地下飛行 blog: http://luo74128.blogspot.com/2010/07/blog-post.html 我: http://www.wretch.cc/album/luo74128 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 222.126.156.188
MOONRAKER:直接用SQL做卡實在 http://goo.gl/m3ceZ 07/31 11:11
luo74128:請問我query要怎麼下? 07/31 11:44
luo74128:SELECT DATE_ADD('".$a->DateTime."', INTERVAL 1 DAY ?? 07/31 11:45
luo74128:我的目的是要把那個欄位update增加7天 07/31 11:47
luo74128:SELECT DATE_ADD(DateTime,INTERVAL 45 DAY) AS DateTime 07/31 12:01
luo74128:謝謝喔 07/31 12:01
kerash:update `xx` set `dt`=date_add(`dt`,interval ? day) 07/31 12:44
kerash: where `id`= ? 07/31 12:44
kerash:上面是一整句的。 07/31 12:44
MOONRAKER:對嘛 更新資料庫欄位正合在資料庫裡做完 07/31 16:21
MOONRAKER:不然拿出來還要strtotime()轉來轉去,煩死人 07/31 16:22
MOONRAKER:當然你有DateTime class好用,不過他要5.2.0以上才有 07/31 16:23