Php datetime set_ day to 1
Should i use date_modify and do some loop or there's other way to change it in easy way rather than looping. Show asked Oct 3, 2013 at 2:56
1
Demo.
Martijn 15.5k4 gold badges36 silver badges66 bronze badges answered Oct 3, 2013 at 7:49
GlavićGlavić 41.7k13 gold badges74 silver badges107 bronze badges 1 You can use the native PHP "date_date_set" function to make this change.
Or using the Object-Oriented style:
answered Jan 22, 2017 at 19:15
Updated: to force to change the day from 27 to 10 1) get the year and month
2) append your day
Also you can finish it in ONE step answered Oct 3, 2013 at 2:58
Allen ChakAllen Chak 1,6591 gold badge9 silver badges21 bronze badges 2 Note: If you're just trying to modify the value of a day on the date that comes from a
submitted
Bono 4,6896 gold badges46 silver badges76 bronze badges answered Oct 3, 2013 at 3:14
Jhonathan H.Jhonathan H. 2,7121 gold badge17 silver badges26 bronze badges 1 Use PCRE Function
preg_replace manual answered Oct 3, 2013 at 4:37
1 How to change date to day in PHP?$date = new DateTime('2006-12-12'); $date->modify('+1 day'); echo $date->format('Y-m-d');
How to modify date in PHP?PHP date_modify() Function
$date=date_create("2013-05-01"); date_modify($date,"+15 days"); echo date_format($date,"Y-m-d");
How can I get plus date in PHP?The date_add() function adds some days, months, years, hours, minutes, and seconds to a date.
How do you check today is the first day of month in PHP?We can do it in many ways. $query_date = '2021-01-10'; // First day of the month. echo date('Y-m-01', strtotime($query_date));
|