In my laravel app i need to compare 2 dateTime, the created_at and the updated_at, but i notice that when i call this properties of the record is not disaplayed the seconds, onlu hour and minutes, i need to get the seconds, what i need to change or include to show all info? I beend checking on the documentation and didnt found anything.
Ex:
$calculation->created_at
output:
2017-03-03 21:03
And in database is:
2017-03-03 21:03:22
What the string output is doesn't effect what the value of the object is. You simply need to compare the two objects to each other.
$dateFromDB = $row['date'];
$compareDateTime = new DateTime('1999-12-31'); // some date
if($compareDateTime < srttotime($dateFromDB))
{
// do stuff...
}
Note the use of strtotime function. This converts a string to a unix timestamp (which is what a DateTime object is under the hood).
In your model, try to add:
protected $dates = ['created_at', 'updated_at'];
this will make them Carbon instances and you should be able to some something like this:
if($calculation->created_at == $calculation->updated_at)
Or any other thing you would do.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.