Comparison of days (larger and smaller)

Asked

Viewed 34 times

0

I found something similar here, but it’s still 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";
  }

Only what happens... It is checking whether it is larger or smaller only by day, example of two results:

"T2= 24102016" > "T3= 22022017" -> Go roll my friend

"T2= 13102016" > "T3 = 22022017" -> You cannot mark the Test

I don’t know, but I don’t understand why he’s just judging the day and not the full pro number...

  • You should use strotime in both variables.

  • @Mauroalexandre I forgot to add, but I’m using the original code, I’ve already edited... but continues my doubt...

  • 1

    What is the value of $start_proofs ?

1 answer

2


You must 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 check that you are mistakenly comparing the variables. Do as I indicated.

  • 1

    Comparing to your code, I saw that what was complicating my life was the format "dmY"... vlw man!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.