Avatar of fastfind1
fastfind1 asked on

Select Date from MySQL using PHP - Need PHP add 10 days to date, keep MySQL date format, update MySql table with new Date in correct format

Using PHP and MySQL, have a table that has a field with the DATE data type.  Hence all records have a format similar to 2008-05-24.  Using PHP I can select the date from the mysql table and assign it a variable ($date_old).  Then, using PHP I need to add 10 days to the date and assign the new date to a new variable $date_new.  How do I do this and preserve the format.  

So if $date_old = '2008-05-24', I need $date_new = '2008-06-03'

How can I do this using PHP?  If I cant use PHP, how can I do this using something compatible with PHP and MySQL?
PHPWeb ApplicationsMySQL Server

Avatar of undefined
Last Comment
vsudip

8/22/2022 - Mon
vsudip

u can use this..for adding days in predefined date in php
$d = mktime(0,0,0,$month,$day,$year);
$end_date = date(Y m d,strtotime(+2 days,$d));
vsudip

The above code will add 2 days in date d
ASKER
fastfind1

I don't recognize the symbols in the last line -- they look like little squares.  Can you tell me what those are?

Also, please fix my code to add 10 days to $date_old:

$date_old = '2008-05-24';
$d = mktime (0,0,0,$month,$day,$year);
$date_new = ?????????
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
pain_is_relative

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
vsudip

You can use this code
$date_old = '2008-05-24';
$date_new= $dateobj->addDays($date_old, +10);