0

First i entered e6 = 24-09-2011 as input type = "text" in previous page then:

  $a6 = $_POST["e6"]   ; 
  $time = strtotime( $a6 );
  $myDate = date ("y-m-d", $time ); 
  echo $myDate ;
  $n = strtotime(date("Y-m-d", strtotime($myDate)) . " +$a7 month");
  $q = date("Y-m-d", $n);
  echo $q ;

out put: 11-09-24 2013-09-24

I want to print 2011 in place of only 11. What should I do ?? pls help.

2
  • just capitalize y in $myDate = date ("y-m-d", $time ); Commented Oct 17, 2012 at 8:54
  • If a user has given you the correct answer. Please accept. Commented Nov 7, 2012 at 11:22

2 Answers 2

3
 $a6 = $_POST["e6"]   ; 
    $time = strtotime( $a6 );
    $myDate = date ("Y-m-d", $time ); 
    echo $myDate ;
    $n = strtotime(date("Y-m-d", strtotime($myDate)) . " +$a7 month");
    $q = date("Y-m-d", $n);
    echo $q ;

You needed to change all the lower case y to capital Y. See here.

Sign up to request clarification or add additional context in comments.

Comments

0

$myDate = date ("y-m-d", $time );
should be with a capital 'Y' like so :
$myDate = date ("Y-m-d", $time );

Php docs has a very good explanation on the data-string formatting: Here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.