[英]problem to Get Date, month Year separately From database in Php File?
我想從數據庫中獲取日期,月份,時間,小時,分鍾,秒,秒,用於倒數計時器,在數據庫中存儲的日期為2010/10/10:我使用此代碼:
$m=date('m',$row['Date']);
$d=date('d',$row['Date']);
輸出是month = 31 date = 12 ...
如果您想分開使用它們,可以將explode
功能與list
一起使用,例如:
list($year, $month, $day) = explode('/', $row['Date']);
另外,您可以使用strtotime
函數獲取單個值:
echo 'Day' . date('d', strtotime($row['Date']));
echo 'Month' . date('m', strtotime($row['Date']));
echo 'Year' . date('Y', strtotime($row['Date']));
$d = // Pull your date from the db
$date = new DateTime($d);
$day = $date->format('l'); // Creates day name
$day = $date->format('j') // Creates date number
$month = $date->format('n'); // Creates month number
$year = $date->format('Y'); // Creates year
..依此類推。
您可以在這里http://php.net/manual/en/function.date.php找到格式設置選項
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.