dombrorj Posted January 6, 2010 Share Posted January 6, 2010 I'm trying to get whatever the date was 3 days ago to display in an html document. And I need is the month on one line and the day on another. If today's date is January 2nd, for example, the date has to display December 31. So my html looks like this... <head> </head> <body> <p>the date 3 days ago was: <br> December <br> 31 </body> Can someone help me with the php code to use here? What I've found so far won't actually display anything in my browser, so I may be doing it entirely wrong. I use other php scripts, and am certain my server has php 5 enabled. But maybe there's something else that has to be enabled? Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/187373-help-with-displaying-date-3-days-ago/ Share on other sites More sharing options...
rajivgonsalves Posted January 6, 2010 Share Posted January 6, 2010 you can use strtotime with date e.g <?php echo date('F d', strtotime("-3 days")); ?> Link to comment https://forums.phpfreaks.com/topic/187373-help-with-displaying-date-3-days-ago/#findComment-989428 Share on other sites More sharing options...
mrbuter Posted January 6, 2010 Share Posted January 6, 2010 edit: got beat Link to comment https://forums.phpfreaks.com/topic/187373-help-with-displaying-date-3-days-ago/#findComment-989432 Share on other sites More sharing options...
dombrorj Posted January 6, 2010 Author Share Posted January 6, 2010 you can use strtotime with date e.g <?php echo date('F d', strtotime("-3 days")); ?> Excellent, thanks! I couldn't get it to work at first when the doc was saved as an html file. Once I saved as a php file and uploaded to server, it worked. Is that necessary? (clearly don't know what I'm doing) One other question... the format of the month is spelled out entirely, i.e. "December" Is there an easy way to make the months abbreviated, i.e. "Dec" Thanks! Link to comment https://forums.phpfreaks.com/topic/187373-help-with-displaying-date-3-days-ago/#findComment-989439 Share on other sites More sharing options...
rajivgonsalves Posted January 6, 2010 Share Posted January 6, 2010 You would have to save your files with .php that is how the server identifies and parses out your php files unless you configure the server differently, for different date formatting you can see the following link http://php.net/manual/en/function.date.php there are examples which show you how you can format your date Link to comment https://forums.phpfreaks.com/topic/187373-help-with-displaying-date-3-days-ago/#findComment-989440 Share on other sites More sharing options...
mrbuter Posted January 6, 2010 Share Posted January 6, 2010 Change the "F" to an "M". http://us.php.net/manual/en/function.date.php Link to comment https://forums.phpfreaks.com/topic/187373-help-with-displaying-date-3-days-ago/#findComment-989441 Share on other sites More sharing options...
dombrorj Posted January 6, 2010 Author Share Posted January 6, 2010 That did it! Thanks to both of you for your help. Much appreciated Link to comment https://forums.phpfreaks.com/topic/187373-help-with-displaying-date-3-days-ago/#findComment-989442 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.