Date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bobbyaa
Forum Newbie
Posts: 17
Joined: Wed Oct 13, 2004 4:54 pm

Date

Post by bobbyaa »

Is there a way to take a date that a user submits, and add to it. For example, they submit the date 03/11/05 and i would add three and it would now have the value of 03/14/05.

Thanks
Robert
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Code: Select all

echo date("m/d/y", strtotime("03/11/05")+(3*24*60*60));
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Code: Select all

echo date("m/d/y", strtotime("03/11/05 + 3 days"));
will do the same

and just for info
Just a comment that the strtotime function supports American date format before it supports English date format.

$input = "02/01/2000";

$time = strtotime($input);

$output = date("Ymd", $time);

For the example date above, the output will be 20000201.

However, for the 29th January 2000 (29/01/2000) the output is 20020501

so it assumes mm/dd/yyyy rather than dd/mm/yyyy
Post Reply