Jump to content

add date function


kony

Recommended Posts

i am trying to make a date function, which well take current date and number of days to be added and well calculate the new date.

But i have problem that wheni add, say example current date = 25 / 03/ 2007 + 7 days, it well give me 32 / 04 / 2007. and expected answer is 1 /05 /2007.

 

is there any function in php that well do this job for me. or i 'll have to write the code to check the case of each month??

Link to comment
https://forums.phpfreaks.com/topic/49469-add-date-function/
Share on other sites

Since all of PHP date based functions assume that the date is in the form mm/dd/yyyy (or yy) or yyyy-mm-dd, you would first have to convert your date to one of those forms before using them.

<?php
$in = '25/03/2007';
list($month,$day,$year) = explode('/',$in);
$out = date('d/m/Y',strtotime($month . '/' . $day . '/' . $year . ' +7 days'));
echo $out;
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/49469-add-date-function/#findComment-242538
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.