1

I am fetching date from database and stored it in a variable called $lastRequest[1]. Now I need to add certain number of days which are stored in variable $licChkFreq to the date stored in $lastRequest[1].

I am using this code:

$nextRequest=$newExp = strtotime(date("Y-m-d", strtotime($lastRequest[1])) . " +".$licChkFreq." day");
$nextRequest=date("Y-m-d",$nextRequest);
jszobody
  • 28,495
  • 6
  • 61
  • 72

1 Answers1

0

Try the following, this should give you what you need.

$newDate = date('Y-m-d', strtotime($lastRequest[1] . " +" . $licChkFreq ." days"));

This is the code I tested with

$lastRequest[1] = '2013-12-11';
$licChkFreq = 7;

$newDate = date('Y-m-d', strtotime($lastRequest[1] . " +" . $licChkFreq ." days"));

echo $newDate;
The Humble Rat
  • 4,586
  • 6
  • 39
  • 73
  • still getting previous date 1970-01-01 – user3068213 Dec 11 '13 at 13:38
  • while if i run only this code it gives correct output. – user3068213 Dec 11 '13 at 13:39
  • Please see my update and test the code I tried with also. If the above works but when using the actual variables it doesn't, then there must be something with those variables that is causing an issue. I would maybe check each variable one by one, ie take my code and feed the `$lastRequest[1]` in first, then the `$licChkFreq`. I would also try `echo date('Y-m-d');` to see what date your server says it is. But can guarantee this is working for me. – The Humble Rat Dec 11 '13 at 13:47
  • The code given by you works if i explicitly define the of $lastRequest[1] and $licChkFreq but if i fetch the values from database it does not work. But i checked that it fetches correct values from database by echoing them on screen. – user3068213 Dec 11 '13 at 13:55
  • I added trim function while fetching values from database and it worked. Maybe it was also fetching whitespace from the database along with the value. – user3068213 Dec 11 '13 at 14:12
  • Yeah I figured something like that was going on, glad you got it working. – The Humble Rat Dec 12 '13 at 08:09