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"; } Link to comment https://forums.phpfreaks.com/topic/102730-solved-strtotime-help-pretty-easy-im-sure/ 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/102730-solved-strtotime-help-pretty-easy-im-sure/#findComment-526084 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 Link to comment https://forums.phpfreaks.com/topic/102730-solved-strtotime-help-pretty-easy-im-sure/#findComment-526090 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. Link to comment https://forums.phpfreaks.com/topic/102730-solved-strtotime-help-pretty-easy-im-sure/#findComment-526094 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? Link to comment https://forums.phpfreaks.com/topic/102730-solved-strtotime-help-pretty-easy-im-sure/#findComment-526099 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? Link to comment https://forums.phpfreaks.com/topic/102730-solved-strtotime-help-pretty-easy-im-sure/#findComment-526104 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 Link to comment https://forums.phpfreaks.com/topic/102730-solved-strtotime-help-pretty-easy-im-sure/#findComment-526106 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. Link to comment https://forums.phpfreaks.com/topic/102730-solved-strtotime-help-pretty-easy-im-sure/#findComment-526110 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.