Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add days to a date (PHP) [duplicate]

Tags:

php

I am saving dates like so: 2013-11-06 using date function

date("Y-m-d")

Would like to add three days to the date. Would I need to use strtotime() for this?

like image 253
twyntee_trey Avatar asked Dec 07 '22 04:12

twyntee_trey


2 Answers

Add days to a date (PHP)

$datetime = new DateTime('2013-01-22');
$datetime->modify('+1 day');
echo $datetime->format('Y-m-d H:i:s');

you may find here more Date time

Update

  • How to find time difference between two dates using PHP: Answer
  • How to calculate the difference between two dates using PHP?: Answer
like image 146
Manwal Avatar answered Dec 08 '22 17:12

Manwal


Here you go

echo date('Y-m-d', strtotime("+3 days"));
like image 42
Mojtaba Avatar answered Dec 08 '22 18:12

Mojtaba