Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I get the 1-day previous date of a dd/mm/yyyy string in PHP?

I have a string, for example:

$date = "01/04/2022";

I want to get the previous day’s date in dd/mm/yyyy format (i.e., 31/03/2022). How do I proceed?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use Datetime Class of PHP to modify the date.

Ex :

$date = "01/04/2022";
$dateTime = DateTime::createFromFormat('d/m/Y', $date);
$dateTime->modify('-1 day');
$previousDate = $dateTime->format('d/m/Y');
echo $previousDate;

Result:

31/03/2022
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading