3
echo date( "F jS, Y" , strtotime("now +3 weeks") );

It gives the result as July 2nd, 2010 . Fine.Now I want to pass the argument like this.

The original print_r($originalamount) give the result like this

Array ( 
      [0] => 4 Months
      [1] => 3500 
)

My code

 $text=trim($originalamount[0]);
 $text1="now +".$text;

 echo date( "F jS, Y" , strtotime($text1)) ;

The out put come like this

December 31st, 1969 

I don't know why.

alt text

svk
  • 4,513
  • 18
  • 63
  • 100
  • 2
    Have you tried hardcoding echo date( "F jS, Y" , strtotime("now +4 Months") ); to see if ti works? – Lizard Jun 11 '10 at 15:13
  • Not exactly related, but where does this "4 months" value come from ? wouldn't it be simpler and **safer** to use an integer (number of months/days/whatever) to represent a time duration instead of a plain string ? – ereOn Jun 11 '10 at 15:16
  • Also, did you try outputting `$text1` before the call to `strtotime()` to see what his value is ? – ereOn Jun 11 '10 at 15:17
  • ya its work fine for me.Only thing is it produce the error when we applied the argument. – svk Jun 11 '10 at 15:18
  • Hi ereOn I print the value it produce like now +4 Months only. – svk Jun 11 '10 at 15:19

1 Answers1

3

I have just tried ...

$originalamount[0] = '4 Months';

$text=trim($originalamount[0]);
$text1="now +".$text;

echo date( "F jS, Y" , strtotime($text1)) ;

And it works fine...

October 11th, 2010 

Can you please give us a var_dump of $originalamount is there any other code that might be messing with $originalamount

Lizard
  • 43,732
  • 39
  • 106
  • 167
  • I tried with different name also.But it wont work I dont know why.If I hard code it its working fine – svk Jun 11 '10 at 15:26
  • can you var_dump($originalamount); place it right before the trim, also echo `$text` and `$text1` to see if they are what you expected – Lizard Jun 11 '10 at 15:29