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)));
精彩评论