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 you are storing strtotime() in $due, then you need to compare it like that, too
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.
I don't know why strtotime didnt work correctly for me. Probably it's because of time zone and other stuff.
As always fancy regular expressions works like a charm. I'm somehow addicted to it!
if(preg_match("/0{4}/" , $dbDateField))
{
// no its not acceptable
}
else
{
//ok
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With