• support@answerspoint.com

How Add Day , Month , Year in PHP Date

2280

I want to add a number value (day,month,year) , when date are in string in mysql date formet ie( dd-mm-yyyy)

ie $my_date='25-11-2015' then i want to add 5 days in

ie $my_date+5day

Inhance

I want to add number of days to current date: I am using following code:

$i=30;
echo $date = strtotime(date("Y-m-d", strtotime($date)) . " +".$i."days");

But instead of getting proper date i am getting this: a long integer value

Please help me on this

 

  • PHP

  • asked 3 years ago
  • B Butts

4Answer


0

Using date() and strtotime() from the docs.

$date = "2012-01-05";

$year = date('Y', strtotime($date));

$month = date('F', strtotime($date));

echo $month
  • answered 2 years ago
  • Gul Hafiz

0

Use strtotime():

$time=strtotime($dateValue);
$month=date("F",$time);
$year=date("Y",$time);
  • answered 2 years ago
  • G John

0

You can use this code:

$dateValue = strtotime('2012-06-05');
$year = date('Y',$dateValue);
$monthName = date('F',$dateValue);
$monthNo = date('m',$dateValue);
printf("m=[%s], m=[%d], y=[%s]\n", $monthName, $monthNo, $year);
  • answered 2 years ago
  • Sunny Solu

0

Add days in php date
$mydate=date("Y-m-d");// or "2017-01-25";
$resultdate = strtotime(date("Y-m-d", strtotime($mydate)) . " 15 days");
/*
//if you use subs day in php date
$resultdate = strtotime(date("Y-m-d", strtotime($mydate)) . "-15 days");
*/
$resultdate=date("Y-m-d",$resultdate);


Add months in php date
$mydate=date("Y-m-d");// or "2017-01-25";
$resultdate = strtotime(date("Y-m-d", strtotime($mydate)) . " 3 monts");
/*
//if you use subs day in php date
$resultdate = strtotime(date("Y-m-d", strtotime($mydate)) . "-3 monts");
*/
$resultdate=date("Y-m-d",$resultdate);

Add years in php date

$mydate=date("Y-m-d");// or "2017-01-25";
$resultdate = strtotime(date("Y-m-d", strtotime($mydate)) . " 3 year");
$resultdate=date("Y-m-d",$resultdate);
?>

  • answered 1 year ago
  • Sunny Solu

Your Answer

    Facebook Share