Day comparison (major and minor)

0

I found something similar here but it still is not what I want. I have the following code in php:

$data_t2 = date('dmY', strtotime($inicio_provas));
$data_t3 = date('dmY', strtotime("+120 days"));
  if ($data_t2 < $data_t3) {
     $data_libera = "Você não pode marcar a Prova";
  }else{
     $data_libera = "Vai rolar meu amigo";
  }

Just what happens ... He is checking if it is bigger or smaller only for the day, example of two results:

  

"T2 = 24102016" > "T3 = 22022017" - > You're going to roll my friend.

     

"T2 = 13102016" > "T3 = 22022017" - > You can not score Proof

I know, but I do not understand why he is only judging the day and not the complete number ...

    
asked by anonymous 25.10.2016 / 22:02

1 answer

2

You should do something like

 $data1 = '2013-05-21';
 $data2 = '2013-05-22';

 if(strtotime($data1) > strtotime($data2)){
  echo 'A data 1 é maior que a data 2.';
 }elseif(strtotime($data1) == strtotime($data2)){
  echo 'A data 1 é igual a data 2.';
 }else{
  echo 'A data 1 é menor que a data 2.';
 }

Please make sure you are comparing the variables incorrectly. Do as I indicated.

    
25.10.2016 / 22:17