Jump to content

getting dates using strtotime or other if possible.


iPixel

Recommended Posts

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!

Link to comment
Share on other sites

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")));

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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"));
				}

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.