datetime - What's the right way to compare two dates in php? -


i need compare dates database current day. id code, in eloquent:

$posts = post::where('date', '=', date('y-m-d'))->get(); 

i want retrieve today's posts only. knowing 'date' field of type date, how make work? tried convert date('y-m-d') string 'format' method, seems date('y-m-d') somehow returning boolean, , thus, method 'format' can't applied it..

i use handle database dates

    //get database date, , format  $database_date = date_format($database_date, 'y-m-d');  //get today date or date of choice $today_date = new datetime();  //format $today_date = date_format($today_date, 'y-m-d');  // use strtotime() compare dates or datetime::diff more cleaner imo $difference = strtotime($today_date) - strtotime($database_date); 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -