AV1611 Posted July 2, 2008 Share Posted July 2, 2008 I need to create a database with two + columns. one needs to have the date as "1/1/2007" and the other as "Monday" sequential through all of 2007. I really just need to figure out how to sequence the php to make all the dates... I can handle the rest... Thanks. Quote Link to comment Share on other sites More sharing options...
mbeals Posted July 2, 2008 Share Posted July 2, 2008 Figure out Jan 1st 2007's time stamp. Make a for loop that runs from 0 to the desired number of days. In the for loop, use date() to generate each date string in the format you want. Take the starting time stamp and add the loop iterator * 86400 and pass that as the time stamp. ie: $start = mktime(0,0,0,1,1,2007); for($i=0;$i<365;$i++){ $ts = $start + ($i * 86400); $date = date("n/j/Y", $ts); $dow = date("l", $ts); } you could also use the time stamp directly: $start = mktime(0,0,0,1,1,2007); $stop = mktime(0,0,0,1,1,2008); for($i=$start;$i<$stop;$i+=86400){ $date = date("n/j/Y", $i); $dow = date("l", $i); } not sure which is better optimized, but they should do the same thing. Just depends on how you would rather choose start/end dates. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 2, 2008 Share Posted July 2, 2008 A date in that format has limited use in a database. You cannot do any greater-than/less-than comparisons and more importantly for what you are doing (some type of calender), you cannot do an ORDER BY that_date_format (you would need to add an auto incrementing index to allow an ORDER BY to output those dates in any correct order.) Also, the day of the week name can be found for any date using a simple DATE_FORMAT() function, so storing the day of week name is redundant information. Quote Link to comment Share on other sites More sharing options...
AV1611 Posted July 2, 2008 Author Share Posted July 2, 2008 actually I am just trying to get the list of dates for a throw away project and will not be running sql against it other than to fill in some data. when it's done I'll export to csv and delete. 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.