简体   繁体   English

从php文件中的数据库分别获取日期,月份年份的问题?

[英]problem to Get Date, month Year separately From database in Php File?

i want to separate date, month, time, hour, min ,sec getting from database, for count down timer, in data base stored date is 2010/10/10: me using this code : 我想从数据库中获取日期,月份,时间,小时,分钟,秒,秒,用于倒数计时器,在数据库中存储的日期为2010/10/10:我使用此代码:

$m=date('m',$row['Date']);
$d=date('d',$row['Date']);

output is month=31 date = 12.... 输出是month = 31 date = 12 ...

If you want them separetely, you can use the explode function with list eg: 如果您想分开使用它们,可以将explode功能与list一起使用,例如:

list($year, $month, $day) = explode('/', $row['Date']);

Also, you can use the strtotime function for getting individual values: 另外,您可以使用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

..and so forth. ..依此类推。

You can find formatting options here, http://php.net/manual/en/function.date.php 您可以在这里http://php.net/manual/en/function.date.php找到格式设置选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM