作者MrMarcus (請勿忘記密碼)
看板PHP
標題Re: [請益] 關於date('Y-m-d')
時間Fri Jun 2 01:36:57 2006
※ 引述《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
1F:→ beautifulin:似乎不能strtotime("+$limitd days") ? 06/02 02:14
2F:→ beautifulin:而且起始時間不是現在是已經存在資料庫的date資料>"< 06/02 02:15
3F:推 ails:int strtotime ( string time [, int now] ) 06/04 01:01
4F:→ ails:int strtotime ( "+{limitd} days" , $unixtime ) 06/04 01:03