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

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

<?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.

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.