Clinton Posted April 24, 2008 Share Posted April 24, 2008 $cdlmedical is a date in my database. I have one row currently and the date in there is 4-4-2007. When I try to add 11 months to it and output it I am getting the default time 12/31/1969. Where am I going wrong? while ($row=mysql_fetch_assoc($result)){ extract($row); echo "$cdlmedical <br />"; $cdlmedical = date('$cdlmedical',strtotime('+ 11 months')); $cdlmedical = date('n/j/Y',strtotime($cdlmedical)); echo "$lname $cdlmedical"; } Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 24, 2008 Share Posted April 24, 2008 <?php while ($row=mysql_fetch_assoc($result)){ extract($row); echo "$cdlmedical <br />"; $cdlmedical = strtotime($cdlmedical.' + 11 months'); $cdlmedical = date('n/j/Y',$cdlmedical); echo "$lname $cdlmedical"; } ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 24, 2008 Share Posted April 24, 2008 Use something like this: <?php $dt = '4-4-2007'; echo date('Y-m-d',strtotime('+11 months',strtotime($dt))) . "<br>"; ?> You really should look at the manual entries for date() and strtotime(). Ken Quote Link to comment Share on other sites More sharing options...
Clinton Posted April 24, 2008 Author Share Posted April 24, 2008 Thanks Guy. And Ken, I did look at the manual. I even looked multiple places. That's how I was able to attempt putting that whole contraption together. I couldn't figure out why it wasn't working so I posted here for help. Thought I was allowed to do that. Quote Link to comment Share on other sites More sharing options...
Clinton Posted April 24, 2008 Author Share Posted April 24, 2008 Here' a question: Why the '.' (dot) after $cdlmedical? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 24, 2008 Share Posted April 24, 2008 because you are using single quotes, and anything in single quotes will be read as text double quotes it will be read as a dynamic string. <?php $cdlmedical = strtotime($cdlmedical.' + 11 months'); // is the same as: $cdlmedical = strtotime("$cdlmedical + 11 months"); ?> is that what your asking? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 24, 2008 Share Posted April 24, 2008 I did look at the manual. I even looked multiple places. That's how I was able to attempt putting that whole contraption together. I couldn't figure out why it wasn't working so I posted here for help. Thought I was allowed to do that. Yes, you're allowed to do that, but when I looked at you code snippet it didn't look like you had seen the manual at all. The '.' is the concatenation operator. Ken Quote Link to comment Share on other sites More sharing options...
Clinton Posted April 24, 2008 Author Share Posted April 24, 2008 That is what I was asking. Thank you for your help. Sorry Ken, next time I'll try to do a little more research. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.