开发者

php extract year/month/day/hour/minute/seconds from a date

开发者 https://www.devze.com 2023-02-21 10:51 出处:网络
if i have a date and i want to extract the year, the month, etc in PHP5, how 开发者_如何转开发should i proceed?

if i have a date and i want to extract the year, the month, etc in PHP5, how 开发者_如何转开发should i proceed?

if i do

 $y = date('Y',$sale->end);  

it doesn't work...


If $sale->end is a valid datestamp, pass it through strtotime() like so:

$y = date('Y', strtotime($sale->end));


As jnpcl indicated, if $sale->end holds a valid datestamp you can do the following:

list($year,$month,$day,$hour,$minute,$second)=explode('-',date('Y-m-d-h-i-s',strtotime($sale->end)));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号