Mutley Posted December 29, 2008 Share Posted December 29, 2008 Is there anyway to find the month before the current month using date( "m" )? I imagine it requires some array or would a unix timestamp time() be more efficient for this? Regards, Nick. Link to comment https://forums.phpfreaks.com/topic/138758-solved-month-before-date-m/ Share on other sites More sharing options...
gevans Posted December 29, 2008 Share Posted December 29, 2008 well if you want to us a timestamp the following is very simple $thestamp = time(); $past = 60*60; //that's an hour 60 seconds times 60 minutes $thestamp -= $past;//timestamp is no placed an hour in the past Link to comment https://forums.phpfreaks.com/topic/138758-solved-month-before-date-m/#findComment-725501 Share on other sites More sharing options...
rhodesa Posted December 29, 2008 Share Posted December 29, 2008 echo date('m',mktime(0,0,0,date('m') - 1,1,date('Y'))); Link to comment https://forums.phpfreaks.com/topic/138758-solved-month-before-date-m/#findComment-725506 Share on other sites More sharing options...
Mutley Posted December 29, 2008 Author Share Posted December 29, 2008 Thanks a lot guys, Could you explain this? I'm sure it will work just I've not seen the mktime function before, looks interesting! echo date('m',mktime(0,0,0,date('m') - 1,1,date('Y'))); Link to comment https://forums.phpfreaks.com/topic/138758-solved-month-before-date-m/#findComment-725512 Share on other sites More sharing options...
rhodesa Posted December 29, 2008 Share Posted December 29, 2008 mktime() take the hour/min/sec/mon/day/year and returns a timestamp: http://php.net/mktime it's great cus you can give it numbers that are too big or small and it will compensate. so in january, the code i gave you would get the 0 month of 2009, which it knows is the 12th of 2008. i also just remembered you should be able to do this: echo date('m',strtotime('-1 month')); Link to comment https://forums.phpfreaks.com/topic/138758-solved-month-before-date-m/#findComment-725526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.