therealwesfoster Posted March 10, 2009 Share Posted March 10, 2009 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 https://forums.phpfreaks.com/topic/148859-solved-get-the-beginning-and-end-timestamps-of-weeks-and-days/ Share on other sites More sharing options...
trq Posted March 10, 2009 Share Posted March 10, 2009 Where exactly are you stuck? Link to comment https://forums.phpfreaks.com/topic/148859-solved-get-the-beginning-and-end-timestamps-of-weeks-and-days/#findComment-781663 Share on other sites More sharing options...
therealwesfoster Posted March 10, 2009 Author Share Posted March 10, 2009 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 https://forums.phpfreaks.com/topic/148859-solved-get-the-beginning-and-end-timestamps-of-weeks-and-days/#findComment-781664 Share on other sites More sharing options...
Mikedean Posted March 10, 2009 Share Posted March 10, 2009 <?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 https://forums.phpfreaks.com/topic/148859-solved-get-the-beginning-and-end-timestamps-of-weeks-and-days/#findComment-781672 Share on other sites More sharing options...
therealwesfoster Posted March 10, 2009 Author Share Posted March 10, 2009 <?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 https://forums.phpfreaks.com/topic/148859-solved-get-the-beginning-and-end-timestamps-of-weeks-and-days/#findComment-781676 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.