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. Quote Link to comment 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. Quote Link to comment 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 ); Quote Link to comment 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? Quote Link to comment 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 ); Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
bschultz Posted May 10, 2009 Author Share Posted May 10, 2009 int(-1) Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 Put this somewhere... var_dump($_GET['day']); Quote Link to comment 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! Quote Link to comment 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.