开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜