tomasd Posted March 4, 2008 Share Posted March 4, 2008 Hi, I'm not sure what am I doing wrong here... <?php $start_day = "01"; $start_month = "01"; $start_year = "2007"; $end_day = "10"; $end_month = "01"; $end_year = "2007"; $start_date = date('Ymd', mktime(0, 0, 0, $start_month, $start_day, $start_year)); $end_date = date('Ymd', mktime(0, 0, 0, $end_month, $end_day, $end_year)); for ($i = $start_date; $i < $end_date; $i++) { echo "$i \n"; $newdate = date('c', $i); echo "$newdate \n"; } ?> I was expecting to see $i incremented by day for both $i and $newdate but I'm getting following instead... 20070101 1970-08-21T07:01:41+00:00 20070102 1970-08-21T07:01:42+00:00 20070103 1970-08-21T07:01:43+00:00 20070104 1970-08-21T07:01:44+00:00 20070105 1970-08-21T07:01:45+00:00 20070106 1970-08-21T07:01:46+00:00 20070107 1970-08-21T07:01:47+00:00 20070108 1970-08-21T07:01:48+00:00 20070109 1970-08-21T07:01:49+00:00 What am I doing wrong? Any help appreciated! Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 4, 2008 Share Posted March 4, 2008 mktime() takes integer values. "01" might be messing it up. quoted strings might be messing it up, but i doubt it. probably the 01, it's not an integer. Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 4, 2008 Share Posted March 4, 2008 This would be much easier $start = mktime(0, 0, 0, $start_month, $start_day, $start_year); $end = mktime(0, 0, 0, $end_month, $end_day, $end_year); for ($i = $start; $i <= $end; $i += 86400) { echo "$i \n"; $newdate = date('c', $i); echo "$newdate \n"; } 86400 is the amount of seconds in a day (60 * 60 * 24) Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 4, 2008 Share Posted March 4, 2008 mktime() takes integer values. "01" might be messing it up. quoted strings might be messing it up, but i doubt it. probably the 01, it's not an integer. PHP isn't strict with variable types. A numeric string can be interpreted as an int/float/double ect... His problem was trying to call date with a 'yyyymmdd' formatted string, and not a timestamp. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 4, 2008 Share Posted March 4, 2008 yes, good point and thanks for clarification on "01" vs. 1. Quote Link to comment Share on other sites More sharing options...
tomasd Posted March 4, 2008 Author Share Posted March 4, 2008 yeah, exactly I don't want all that garbage passed on, only date Also note the date it says 1970, it starts unix timestamp from the beginning and runs for the number of days incrementing it by second... 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.