看板 PHP 關於我們 聯絡資訊
※ 引述《jlshen (阿倫)》之銘言: : ※ 引述《beautifulin (要堅強喔!)》之銘言: : : 資料庫存了一個變數$startdate是date('Y-m-d') : : //因為不是Y-m-d不能存進date型態的欄位 : : 我想要把時間推前$limitd=3; : : 該怎麼做呢? : : 如果是date(Ymd)我就能直接+$limitd 但是有'-'情況下就會加到Y去且md和'-'不見了 : : 如果用explode分成 picese[0] picese[1] picese[2] : : 原本個位數字的日期就不能是0X的型態 : : 不知道各位有沒有什麼好方法?<(_ _)>拜託了 : 看不太懂你的問題 : $startdate = "2006-06-01"; : $limitd = 3; : $enddate = date("Y-m-d",strtotime($stardate)+86400*$limitd); : // $limitd 天後的日期 : 不曉得這是不是你要的? 其實strtotime有更簡單的用法喔: $enddate = date("Y-m-d, strtotime("+3 days")); strtotime("+3 days") 就會傳回"三天後的現在"的unix timestamp, 可以用很直覺的方式來敘述指定的時間,不需要自己用計算的。其他 例如要取得"下星期五"的timestamp,可以用strtotime("next Friday"), "下個月的今天"=>strtotime("+1 month")(不用去管這個月有幾天); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.153.19
beautifulin:似乎不能strtotime("+$limitd days") ? 06/02 02:14
beautifulin:而且起始時間不是現在是已經存在資料庫的date資料>"< 06/02 02:15
ails:int strtotime ( string time [, int now] ) 06/04 01:01
ails:int strtotime ( "+{limitd} days" , $unixtime ) 06/04 01:03