php date 1 month earlier
well im using this function to get the summer time in mexico.
function horarioVerano() {
$year = date("Y");
$ahora = strtotime(date("d-m-Y"));
$inicio_invierno = strtotime("last Sunday April $year");
//echo date('Y-m-d H:i:s', $inicio_invierno);
$fin_invierno = strtotime("last Sunday November $year");
//echo date('Y-m-d H:i:s', $fin_invierno);
if ($ahora > $inicio_invierno &&am开发者_如何学运维p; $ahora <= $fin_invierno)
$num = 5;
else
$num = 6;
return $num;
}
but i always get the previous month date, if i echo date("Y-m-d",$inicio_invierno)
i get 2011-03-27 and not 2011-04-24 as it should be , same for any other month i walways get the previous month
"last Sunday April $year" is parsed as "April $year" (which gives the first of the month) and then calculating "last Sunday" relative to that. If you want the last Sunday of April, say just that: "last Sunday of April $year". See the documentation for details.
What exactly is the point of this?
$ahora =strtotime(date("d-m-Y"));
You build a string-based date, then turn it back into a time value (which is an integer) with strtotime(). What a waste of CPU cycles. How about
$ahora = time();
instead?
精彩评论