bschultz Posted May 10, 2009 Share Posted May 10, 2009 I can't seem to find any documentation on how to apply mktime to a variable. I have a url that will pass a date in the format of: xxxx-x-x I need to take that date, and find the previous month to that variable. Since I couldn't find any documentation on how to apply it to a variable, I tried this...which didn't work. $day = $_GET['day']; $previousmonth = "$day mktime(0, 0, 0, date('m')-1)"; How is this supposed to be done? Thanks. Link to comment https://forums.phpfreaks.com/topic/157625-solved-mktime-to-a-variable/ Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 I'm guessing the xxxx is the year. What's the other two? Can't you use explode on the hyphen, grab the month part and subtract 1 from it? You don't need mktime. Link to comment https://forums.phpfreaks.com/topic/157625-solved-mktime-to-a-variable/#findComment-831207 Share on other sites More sharing options...
bschultz Posted May 10, 2009 Author Share Posted May 10, 2009 I get an "invalid day" error on this code $day = $_GET['day']; $data = "$day"; list($year, $month, $date) = explode("-", $data); $previousmonth = ($month - 1); $thisyear = date("Y"); // find out the number of days in the month $numdaysinmonth = cal_days_in_month( CAL_GREGORIAN, $previousmonth, $thisyear ); Link to comment https://forums.phpfreaks.com/topic/157625-solved-mktime-to-a-variable/#findComment-831220 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 1. What is up with people doing $data = "$day";? There's no need to put quotes around the variable like that. 2. What is the full error message? Can you copy and paste the error message? Link to comment https://forums.phpfreaks.com/topic/157625-solved-mktime-to-a-variable/#findComment-831221 Share on other sites More sharing options...
bschultz Posted May 10, 2009 Author Share Posted May 10, 2009 Warning: cal_days_in_month() [function.cal-days-in-month]: invalid date. in daily.php on line 42 This is line 42 $numdaysinmonth = cal_days_in_month( CAL_GREGORIAN, $previousmonth, $thisyear ); Link to comment https://forums.phpfreaks.com/topic/157625-solved-mktime-to-a-variable/#findComment-831222 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 Can you put: var_dump($previousmonth); After $previousmonth = ($month - 1); ? What does that output? Link to comment https://forums.phpfreaks.com/topic/157625-solved-mktime-to-a-variable/#findComment-831226 Share on other sites More sharing options...
bschultz Posted May 10, 2009 Author Share Posted May 10, 2009 int(-1) Link to comment https://forums.phpfreaks.com/topic/157625-solved-mktime-to-a-variable/#findComment-831230 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 Put this somewhere... var_dump($_GET['day']); Link to comment https://forums.phpfreaks.com/topic/157625-solved-mktime-to-a-variable/#findComment-831234 Share on other sites More sharing options...
bschultz Posted May 10, 2009 Author Share Posted May 10, 2009 I got it...$_GET[day] was in 2009-18-06 format...when it should have been 2009-06-18 format. Thanks...again! Link to comment https://forums.phpfreaks.com/topic/157625-solved-mktime-to-a-variable/#findComment-831238 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.