Problem with date!

Asked

Viewed 33 times

2

I have this piece of code:

if ($informations->fundation_date != $dateFoundation) {
    echo 'estou no echo diferente do date';
    $alter .= 'fundation_date/';
} else {
    echo 'esta igual date';
}

echo'data antiga: '.$informations->fundation_date;
echo'data nova: '.$dateFoundation;

Postgree database usage; I’m comparing whether or not the date changed in the input, but even when I do not change the date it comes different. For in the bank (fundation_date) comes as 1995-05-11 and already in the input 05/11/1995. How can I do it, but may they be the same?

  • When you write to the database, you have to write with the yyyy-mm-dd format. When writing to the database treat the date as a string manipulating it to look like this.

  • see this: http://php.net/manual/en/datetime.format.php has to handle the date. when saving to the database save as format you want.

1 answer

0


You can use two functions together: date() and strtotime().

$dateFoundation = $_POST['data'];
$dateFoundation = date('Y-m-d', strtotime($dateFoundation));

if($informations->fundation_date != $dateFoundation){
   echo "Diferente!";
}
else{
   echo "Igual!";
}
  • this does not solve the question since even when does not change the date it comes different. have to treat the string in a way that is equal, only this.

  • So answer there, @Luísalmeida. Talk that doesn’t solve, many people talk.

  • calm dude. I just tried to clarify that what you wrote is correct but it does not solve the problem. I commented on her question ... maybe it helps. : ) abr

  • @Gumball I tried here and ended up giving error in strtotime function().

  • Which error gave ? Edits your question and puts...

  • @Gumball worked like you just said! Thank you so much.

Show 1 more comment

Browser other questions tagged

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