Jump to content

[SOLVED] Get the beginning and end timestamps of weeks and days


therealwesfoster

Recommended Posts

I'm needing to generate a total of 4 UNIX Timestamps.

1. The beginning timestamp of the current week (Sunday at 0:00:00)

2. The ending timestamp of the current week (Saturday at 23:59:59)

3. The beginning timestamp of the current day (today at 0:00:00)

4. The ending timestamp of the current day (today at 23:59:59)

 

The current day/week of the script can be whenever, so the script should be able to function no matter what day/month/year it is :)

 

Thanks!

 

Wes

Link to comment
Share on other sites

I'm having trouble getting the 4 timestamps.

 

I had to do this for the previous month's beginning/ending timestamp and I did it like this:

$prev_month1 = strtotime(date("1 F Y",strtotime('-1 month')));
$prev_month2 = strtotime(date("t F Y",strtotime('-1 month')));

 

This snippet gets the beginning and ending timestamp for the previous month. I'm needing to do the same for the current week and current day.. but I'm stuck

 

Wes

Link to comment
Share on other sites

<?php
$weekStart = strtotime( "-1 Sunday 00:00" );
$weekEnd = strtotime( "+1 Saturday 23:59" );
$todayStart = strtotime( "00:00" );
$todayEnd = strtotime( "23:59" );

echo date( "d/m/y H:i", $weekStart ) . "<br />";
echo date( "d/m/y H:i", $weekEnd ) . "<br />";
echo date( "d/m/y H:i", $todayStart ) . "<br />";
echo date( "d/m/y H:i", $todayEnd ) . "<br />";
?>

 

That should do the trick.

Link to comment
Share on other sites

<?php
$weekStart = strtotime( "-1 Sunday 00:00" );
$weekEnd = strtotime( "+1 Saturday 23:59" );
$todayStart = strtotime( "00:00" );
$todayEnd = strtotime( "23:59" );

echo date( "d/m/y H:i", $weekStart ) . "<br />";
echo date( "d/m/y H:i", $weekEnd ) . "<br />";
echo date( "d/m/y H:i", $todayStart ) . "<br />";
echo date( "d/m/y H:i", $todayEnd ) . "<br />";
?>

 

That should do the trick.

 

 

You're awesome. Thanks!

 

Wes

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.