简体   繁体   English

strtotime不与TIME合作?

[英]strtotime not working with TIME?

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. 我的mysql列有这个日期时间值, 2011-04-11 11:00:00当我应用strtotime然后它的返回日期少于今天,而它应该比今天更大。

also when I am trying this strtotime(date('d/m/Y h:i A')); 当我尝试这个strtotime(date('d/m/Y h:i A')); code, its returning wrong values. 代码,它返回错误的值。 Is there any problem with giving TIME in strtotime? 在strtotime给TIME时有什么问题吗?

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? 基本上我想做的,是将我的mysql列日期与今天的日期进行比较,如果它将来显示“即将到来”其他什么都没有显示?

Please help and advise, what should I do? 请帮忙并告知,我该怎么办?

Edited code 编辑过的代码

$_startdatetime = $rs['startdatetime'];
$_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 . $rs['startdatetime']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. $_startdatetime其值未格式化为即将发生的条件为false,因此返回为mysql值。

d/m/Y h:i A is irreversible ( with strtotime ) format, use standard formats or use time() as recommended by Joel & Rocket d/m/Y h:i A是不可逆转的( 使用strtotime )格式,使用标准格式或使用Joel&Rocket建议的time()

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 OUTPUT

替代文字

SOLUTION

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM