fantomel Posted October 8, 2010 Share Posted October 8, 2010 hello i got this small function i`m working on to get the date of a month something like get current date - 1 but not sure how to handle jan month can someone help me please ? $month = date('m') - 1;$date_startt = date('Y').'-'.$luna.'-01';$timestamp_start = strtotime($data_start); Quote Link to comment https://forums.phpfreaks.com/topic/215462-date-time-function/ Share on other sites More sharing options...
BlueSkyIS Posted October 8, 2010 Share Posted October 8, 2010 can you explain what your final result should be? also, where is $luna defined? Quote Link to comment https://forums.phpfreaks.com/topic/215462-date-time-function/#findComment-1120402 Share on other sites More sharing options...
fantomel Posted October 8, 2010 Author Share Posted October 8, 2010 can you explain what your final result should be? also, where is $luna defined? umm sorry my bad $month = date('m') - 1;$date_startt = date('Y').'-'.$month.'-01';$timestamp_start = strtotime($date_startt); well the final result should be like this: today : Sat 31 Oct 2010 and i want to find out the date of a month ago and if it's January you know that Jan sometimes got +1 day or -1 one day and i need to calculate this correct. Quote Link to comment https://forums.phpfreaks.com/topic/215462-date-time-function/#findComment-1120403 Share on other sites More sharing options...
BlueSkyIS Posted October 8, 2010 Share Posted October 8, 2010 The number of days in January never changes. Do you mean February? Here is how I would get the time of one month ago: $now_parts = get_date();$time_one_month_ago = mktime($now_parts['hours'], $now_parts['minutes'], $now_parts['seconds'], $now_parts['mon'] - 1, $now_parts['mday'], $now_parts['year']); but if you want 30 days instead of 1 month it would be this: $now_parts = get_date();$time_one_month_ago = mktime($now_parts['hours'], $now_parts['minutes'], $now_parts['seconds'], $now_parts['mon'], $now_parts['mday'] - 30, $now_parts['year']); Quote Link to comment https://forums.phpfreaks.com/topic/215462-date-time-function/#findComment-1120418 Share on other sites More sharing options...
jcbones Posted October 8, 2010 Share Posted October 8, 2010 $date = new DateTime(); $date->sub(new DateInterval('P1M')); echo $date->format('m-d-Y'); Quote Link to comment https://forums.phpfreaks.com/topic/215462-date-time-function/#findComment-1120420 Share on other sites More sharing options...
BlueSkyIS Posted October 8, 2010 Share Posted October 8, 2010 ^ Gosh, that is so much more concise. Thanks for that. I must remember the DateTime object... Quote Link to comment https://forums.phpfreaks.com/topic/215462-date-time-function/#findComment-1120423 Share on other sites More sharing options...
fantomel Posted October 9, 2010 Author Share Posted October 9, 2010 thank you very much for you responses. Quote Link to comment https://forums.phpfreaks.com/topic/215462-date-time-function/#findComment-1120431 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.