English 中文(简体)
日期:00
原标题:Check if $date is equal to 0000-00-00 00:00:00
  • 时间:2012-01-13 16:36:17
  •  标签:
  • php
  • date

I want a logic if $due is equal to no date then I want data starting with 2000. My code below is not working.

if($due ==  0000-00-00 00:00:00 ){
    $due =  strtotime( 2000-00-00 00:00:00 );
}
最佳回答

如果你在预留时间(时间)时,需要与时俱进。

if($due == strtotime( 0000-00-00 00:00:00 )){
    $due =  strtotime( 2000-00-00 00:00:00 );
}

or, more simply

if($due == 0){
    $due =  strtotime( 2000-00-00 00:00:00 );
}

but if $due is coming from your db as a string, you would want to strtotime() it:

$due = strtotime($due);
if($due == 0){
    $due =  strtotime( 2000-00-00 00:00:00 );
}

Be aware of timezones, though. That is, strtotime( 0000-00-00 00:00:00 UTC ) != strtotime( 0000-00-00 00:00:00 EST ). This could also break your compare.

问题回答

我不知道,为什么花时间为我做的工作是正确的。 也许,它会因为时间区和其他陷阱而消失。

经常表达方式总是像一种药剂。 我 some不ed地指责它!

if(preg_match("/0{4}/" , $dbDateField))
{
    // no its not acceptable
}
else
{
    //ok
}

I know that this is an old question but this answer may help somebody

准时返回一个成功时段,FALSE不然。

$test = strtotime($due);  
$due  = (!$test || $test < 0) ?  2000-00-00 00:00:00  : $due;

unset($test);

regards.

你们需要确保你以同样的方式对数值进行比较。 根据你目前的情况,在三个问题上将发生:

  • If $due is an int, the string you are comparing it with 0000-00-00 00:00:00 will be converted to an int, which will result in 0, and $due will be compared with 0. This will only result in a match if $due === 0.
  • If $due is a bool, the string will be converted to a bool, which will result in TRUE, and you will only get a match if $due === TRUE.
  • If $due is any other type, it will be converted to a string and the two will be compared as strings. You will only get a match if $due === 0000-00-00 00:00:00 .

If would say that you probably need to compare the values as integers. This means that you need to pass any strings through strtotime() - including $due, if it is a string. Since you do not show an example value of $due I cannot provide an exact working code.

strtotime (YourDate) ! NUL 工作罚款。

我正在数据库的一个DOB和DOM(结婚日期)。 Seems the NUL的违约时间为0000-00-00。 什么是诚实的 st。

或者,也许我倾向于把外地变成一个DATE领域,而不是使其成为一个VARCHAR,并在那里拥有STRTOTIM值。

<?php 
    if(strtotime($dates->dom) != NULL) 
    {
        echo  <a href="  . base_url() .  dates/dom/  . $dates->dom .  ">  . date( j F, Y ,strtotime($dates->dom)) .  </a> ;
    } 
    else 
    { 
        print  Not Listed Yet ;
    } ?></strong>

i would like to suggest simplest form

if(!$due)
        $due =  strtotime( 2000-00-00 00:00:00 );

Here is solution to check if datetime field in database (mysql) is null or 0000-00-00 00:00:00

selecting all with starttime is null or 0000-00-00 00:00:00 and endtime is not ( null or 0000-00-00 00:00:00 )

数据库末

select * from table where IFNULL(MONTH(starttime),0) >= 1 and IFNULL(MONTH(endtime),0) < 1;

if((int)$starttime && !(int)$endtime){  ///  }




相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签