Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare dates not working

Tags:

php

Hallo,

I am comparing 2 dates. It is clear that $db_minus7 is greater so the value of $can_invoiced should be 'maybe' but it is 'Yes'. When i execute.

<?php

$db_minus7 = '2010-07-05 09:45:29.420';
$completion_date = '30.07.2009';
if(date("m-d-Y",strtotime($db_minus7)) > date("m-d-Y",strtotime($completion_date))) {
    $can_invoiced = 'maybe';
} else {
    $can_invoiced = 'Yes';
}

echo $can_invoiced;

?>

please help

like image 446
satya Avatar asked Jan 22 '23 09:01

satya


1 Answers

why don't you just compare the times instad of formating them again like this:

if(strtotime($db_minus7) > strtotime($completion_date)) {
    $can_invoiced = 'maybe';
} else {
    $can_invoiced = 'Yes';
}

EDIT:

if you want to use date(), use "Ymd" or "Y-m-d" as pattern because it's string-comparision, and this is the logical order to work with (arrange the patterns from "big"(years) to small (days... or maybe seconds, if you need));

like image 104
oezi Avatar answered Feb 01 '23 18:02

oezi