I need to aggregate all data in MySQL table which is older than the current month. Expect the current month. So now I should find all records that are older than the first day of the current month. I use
$now = new \DateTime() which returns . the current date and now I need to replace the day with 1 or 01. So what is the best way to do it?
I have found a very nice way to do it. It works with PHP 7.1 I guess with other versions as well
$startOfCurrentMonth = new \DateTime('first day of this month');
BTW it also works for the last day
$endOfCurrentMonth = new \DateTime('last day of this month');
in case if month and year is geven than in order to find the first and end date of that month the following code will help
$date = ['y' => 2019, 'm' => 4]; $monthStartDate = new \DateTime(); $monthStartDate->setDate($date['y'], $date['m'], 1); $monthEndDate = new \DateTime(); $monthEndDate->setDate($date['y'], $date['m'], 1); $monthEndDate->modify('last day of this month');
- 3how to find query parameters from url ?
- 1PHP Switch Statements with 2 Variables at a time
- 1How do I retrieve all 60 years old above using birth_date in PHP PDO?
- 1How to change PHP CLI and Apache versions on Ubuntu
- 1How to skip first n lines of grep result
- 2Linux/ How can I Find All Files Containing Specific text ?
- 0how to find next element of current element?
- 2How to update SQL database with PHP script
- 2PHP redirect function
- 1How to prevent SQL injections in PHP
- 2How to move logging from PHP-FPM to Nginx