iPixel Posted July 30, 2010 Share Posted July 30, 2010 so i have a basic html table and down the left column i have monday,tuesday,wednesday.... sunday. In the column 2nd from the left, i want to fill it with the current weeks dates, which is really based on the current date. So if today is Jul 29th Friday, then strtotime("last monday") would give me Jul 26th Monday... my issue is "last monday" wont work if today is monday because that will give me 19th of july... and since I technically dont know what day is today i'm not sure how to cleanly work around this without having to use some if statement... if today is monday do "last monday +7 days" or just do "now" etc... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/209349-getting-dates-using-strtotime-or-other-if-possible/ Share on other sites More sharing options...
TOA Posted July 30, 2010 Share Posted July 30, 2010 Can you post what code you have so we can see what you've tried Quote Link to comment https://forums.phpfreaks.com/topic/209349-getting-dates-using-strtotime-or-other-if-possible/#findComment-1093133 Share on other sites More sharing options...
iPixel Posted July 30, 2010 Author Share Posted July 30, 2010 Here's the table itself. <table cellpadding="3" cellspacing="0" style="border:1px solid #CCCCCC;" width="100%"> <tr> <td align="center" style="border-right:1px solid #CCCCCC; background-color:#ebebeb;" width="100"> </td> <td align="center" style="border-right:1px solid #CCCCCC; background-color:#ebebeb;" width="100"> <strong>Date</strong></td> <td align="center" style="border-right:1px solid #CCCCCC; background-color:#ebebeb;" width="100"> <strong>In(1)</strong></td> <td align="center" style="border-right:1px solid #CCCCCC; background-color:#ebebeb;" width="100"> <strong>Out(1)</strong></td> <td align="center" style="border-right:1px solid #CCCCCC; background-color:#ebebeb;" width="100"> <strong>In(2)</strong></td> <td align="center" style="border-right:1px solid #CCCCCC; background-color:#ebebeb;" width="100"> <strong>Out(2)</strong></td> <td align="center" style="background-color:#ebebeb;" width="100"> <strong>Hours Worked</strong></td> </tr> <tr> <td align="left" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> <strong>Monday</strong></td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-top:1px solid #CCCCCC;"> </td> </tr> <tr> <td align="left" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> <strong>Tuesday</strong></td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-top:1px solid #CCCCCC;"> </td> </tr> <tr> <td align="left" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> <strong>Wednesday</strong></td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-top:1px solid #CCCCCC;"> </td> </tr> <tr> <td align="left" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> <strong>Thursday</strong></td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-top:1px solid #CCCCCC;"> </td> </tr> <tr> <td align="left" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> <strong>Friday</strong></td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-top:1px solid #CCCCCC;"> </td> </tr> <tr style="background-color:#fffcd3;"> <td align="left" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> <strong>Saturday</strong></td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-top:1px solid #CCCCCC;"> </td> </tr> <tr style="background-color:#fffcd3;"> <td align="left" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> <strong>Sunday</strong></td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-right:1px solid #CCCCCC; border-top:1px solid #CCCCCC;"> </td> <td align="center" style="border-top:1px solid #CCCCCC;"> </td> </tr> <tr> <td colspan="6" align="right" style="border-top:1px solid #CCCCCC; border-right:1px solid #CCCCCC;"> <strong>Total Hours:</strong> </td> <td align="center" style="border-top:1px solid #CCCCCC; background-color:#990033;"> <span style="color:#ebebeb; font-weight:bold;"> #### </span> </td> </tr> </table> </td> </tr> </table> So it's the 2nd column i have to populate based on current weeks dates. So in essence the dates would change with each new week. As for php code i'm just trying to figure out the dates themselves. $today = strtoupper(date("d-M-Y", strtotime("today"))); is there even such a way to say $monday= strtoupper(date("d-M-Y", strtotime("this weeks monday"))); Quote Link to comment https://forums.phpfreaks.com/topic/209349-getting-dates-using-strtotime-or-other-if-possible/#findComment-1093134 Share on other sites More sharing options...
iPixel Posted July 30, 2010 Author Share Posted July 30, 2010 Another option would be to get a start date ie:monday and get the end date ie:sunday / mon+7 And somehow just generate the dates in between, but i'm not sure how to do that if monday is the 29th. How would i know when to stop at 29/30/31 and reset back to 1 for a new month. Quote Link to comment https://forums.phpfreaks.com/topic/209349-getting-dates-using-strtotime-or-other-if-possible/#findComment-1093135 Share on other sites More sharing options...
aleX_hill Posted July 30, 2010 Share Posted July 30, 2010 Try using date("D"); So: if(date("D") == "Mon") $startOfWeek = date("d-M-Y"); //note that strtotime("today") is ignored else $startOfWeek = date("d-M-Y",strtotime("last Monday")); Quote Link to comment https://forums.phpfreaks.com/topic/209349-getting-dates-using-strtotime-or-other-if-possible/#findComment-1093136 Share on other sites More sharing options...
TOA Posted July 30, 2010 Share Posted July 30, 2010 I guess I'm unclear on what you're shooting for. Are you making a calendar that shows one week at a time? Quote Link to comment https://forums.phpfreaks.com/topic/209349-getting-dates-using-strtotime-or-other-if-possible/#findComment-1093142 Share on other sites More sharing options...
iPixel Posted July 30, 2010 Author Share Posted July 30, 2010 I though about doing this but then the issue becomes... if(date("D") = "Tue") do this else do that the issue is, the do "that" part.. it's just going to cause yet another if statement checking that the "D" really is only so that i can do strtotime("last tuesday") or strtotime("next tuesday"). am i wrong? Quote Link to comment https://forums.phpfreaks.com/topic/209349-getting-dates-using-strtotime-or-other-if-possible/#findComment-1093143 Share on other sites More sharing options...
iPixel Posted July 30, 2010 Author Share Posted July 30, 2010 I think this might work. if(date("D") == "Mon") { $monday = date("d-M-Y"); //note that strtotime("today") is ignored $tuesday = date("d-M-Y",strtotime("next tuesday")); $wednesday = date("d-M-Y",strtotime("next wednesday")); $thursday = date("d-M-Y",strtotime("next thursday")); $friday = date("d-M-Y",strtotime("next friday")); $saturday = date("d-M-Y",strtotime("next saturday")); $sunday = date("d-M-Y",strtotime("next sunday")); } if(date("D") == "Tue") { $monday = date("d-M-Y",strtotime("last monday")); $tuesday = date("d-M-Y"); //note that strtotime("today") is ignored $wednesday = date("d-M-Y",strtotime("next wednesday")); $thursday = date("d-M-Y",strtotime("next thursday")); $friday = date("d-M-Y",strtotime("next friday")); $saturday = date("d-M-Y",strtotime("next saturday")); $sunday = date("d-M-Y",strtotime("next sunday")); } if(date("D") == "Wed") { $monday = date("d-M-Y",strtotime("last monday")); $tuesday = date("d-M-Y",strtotime("next wednesday")); $wednesday = date("d-M-Y"); //note that strtotime("today") is ignored $thursday = date("d-M-Y",strtotime("next thursday")); $friday = date("d-M-Y",strtotime("next friday")); $saturday = date("d-M-Y",strtotime("next saturday")); $sunday = date("d-M-Y",strtotime("next sunday")); } Quote Link to comment https://forums.phpfreaks.com/topic/209349-getting-dates-using-strtotime-or-other-if-possible/#findComment-1093149 Share on other sites More sharing options...
aleX_hill Posted July 30, 2010 Share Posted July 30, 2010 I think you might be looking at it the wrong way. <?php if(date("D") == "Mon") { $currentDay = time(); //note that strtotime("today") is ignored } else { $currentDay = strtotime("last Monday"); } //Now we have a timestamp in the first day of the week (Mon) ?> <table> <?php for($i=0; $i<7; $i++) //Do this for 7 days { echo "<tr><td>".date("l",$currentDay)."</td><td>".date("d-M-Y",$currentDay)."</td></tr>"; //Output each line in the table $currentDay += 24*60*60; //add 24 hours to the timestamp to get the next day (Tue, then Wed etc) } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/209349-getting-dates-using-strtotime-or-other-if-possible/#findComment-1093154 Share on other sites More sharing options...
aleX_hill Posted July 30, 2010 Share Posted July 30, 2010 so which code solved it, yours or mine? Quote Link to comment https://forums.phpfreaks.com/topic/209349-getting-dates-using-strtotime-or-other-if-possible/#findComment-1093159 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.