Php: Add variable amount days to Y-m-d date format

muffin

i'm trying to add days to a date with the 'Y-m-d' format:

$oldDate = '2013-05-15';
$newDate = date('Y-m-d', strtotime($oldDate. " + 5 days"));

This ouputs '2013-5-20', but below:

$oldDate = '2013-05-15';
$addedDays = 5;
$newDate = date('Y-m-d', strtotime($oldDate. " + $addedDays days"));

doesn't work, it only outputs '1970-01-01', which doesn't make sense because i only tried to put the days to be added in a variable. They're basically the same code. I appreciate the help trying to understand this. Thanks!

Javad

However the code is right and works, just in case try

$newDate = date('Y-m-d', strtotime($oldDate. " + {$addedDays} days"));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to add days to actual date(Y-m-d)?

How to change date format d/m/Y to Y-m-d PHP

Change the Format of Input for a date from Y/M/D to D/M/Y in SQL/PHP from a form

Add Days to PHP Variable

invalid date error for %m%d%Y format

Invalid date format issue in laravel for d/m/y format

What is the difference between compare two date as string with format (Y-m-d h:i:s) and two date with strtotime of date in php?

php - Output date in d-m-Y format from MySQL timestamp column

Check if date is in 'Y-m-d' format and is not in future date?

PHP date format variable

Trying to add number of days to date but format is wrong

Mysql- Add days to date with different format

Laravel date format in submission form (d-M-Y)

django default date to be in format %d-%m-%Y

How to sort date format d/m/y on bootstrap datatables plugin?

Manipulating datestamp string consistently with date format %Y%m%d

How to extract the values of a date in y-m-d format?

Date Comparison in MYSQL format d-m-Y

how to transform Carbon date into m-d-y format? (opposite)

Parse a date from a format like: "%B %d, %Y" to a format: "%Y-%m-%d" in R

How to add days to a variable date in twig

Database has the date format Y.M.D H: i: s but my BETWEEN has the date format Y.M: D

PHP: strtotime() doesn't add the correct amount of days

Date format M-Y

NVD3 output date format in tooltip as %d/%m/%y and x-axis date as %d/%m

Date format changes from D-M-Y to M-D-Y

Pandas:How to convert date format %Y-%M-%D into %Y%M%D?

Convert Y-m-d date format to d-m-Y

PHP: How to compare months and days( "m-d" dates) with year, month and days ("y-m-d" dates)