开发者

strtotime not working with TIME?

开发者 https://www.devze.com 2023-02-03 12:44 出处:网络
My mysql column has this datetime value, 2011-04-11 11:00:00 when I am applying strtotime then its returning date less than today,whereas it should be greater than today.

My mysql column has this datetime value, 2011-04-11 11:00:00 when I am applying strtotime then its returning date less than today,whereas it should be greater than today.

also when I am trying this strtotime(date('d/m/Y h:i A')); code, its returning wrong values. Is there any problem with giving TIME in strtotime?

Basically I want to do, is to compare my mysql column date with today's date, if its in future then show "Upcoming" else show nothing?

Please help and advise, what should I do?

Edited code

$_startdatetime = $rs['startdatetime开发者_JS百科'];
$_isUpcoming = false;
if(!empty($_startdatetime)){
    $TEMP_strtime = strtotime($_startdatetime);
    $TEMP_strtime_today = strtotime(date('d/m/Y h:i A'));
    if($TEMP_strtime_today < $TEMP_strtime){
        $_isUpcoming = true;
        $_startdatetime = date('l, d F, Y h:i A' ,$TEMP_strtime);
    }
}

And the value in $rs['startdatetime'] is 2011-04-11 11:00:00. And with this value I am getting following output.

$TEMP_strtime - 1302519600
$TEMP_strtime_today - 1314908160
$_startdatetime - 2011-04-11 11:00:00 

$_startdatetime its value is not formatted as the upcoming condition is false, so returning as is mysql value.


d/m/Y h:i A is irreversible (with strtotime) format, use standard formats or use time() as recommended by Joel & Rocket

PROBLEM

<?php
echo $today = date('d/m/Y h:i A');
echo '<br />';
echo $time = strtotime($today);
echo '<br />';
echo date('d/m/Y h:i A', $time);

OUTPUT

strtotime not working with TIME?

SOLUTION

<?php
$today = strtotime(date('m/d/Y h:i:s')); <- use appropriate format
// OR 
$today = time(); @credit to Joel & Rocket
0

精彩评论

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