Page 1 of 1

Timestamp for beginning of the week?

Posted: Wed Sep 03, 2008 6:29 am
by pjjacobs
Hi

Can please somebody help me with this piece of code.

I need to determine 3 things, 1 the duration in seconds from the beginning of the month to the current time, beginning of the week to current time and then beginning of the day to the current time.

So first i need to determine the begin timestamp for each.

Now i have the following:

For the month begin timestamp i have:

Code: Select all

$date_today = date("Y-m-d", time());
list($year_cur, $month_cur, $day1) = split('-', $date_today);
$month_start_cur = gmmktime (0,0,0, $month_cur, 1, $year_cur);
For the Day begin timestamp i have:

Code: Select all

$date_today = date("Y-m-d", time());
list($year_cur, $month_cur, $day1) = split('-', $date_today);
$day_start_cur = gmmktime (0,0,0, $month_cur, $day1, $year_cur);
But i cant seem to get anything working for the first monday of the week??? Any help? :drunk:

Re: Timestamp for beginning of the week?

Posted: Wed Sep 03, 2008 11:40 am
by andyhoneycutt

Code: Select all

$last_monday = strtotime("last Monday");

Re: Timestamp for beginning of the week?

Posted: Fri Sep 05, 2008 1:10 am
by pjjacobs
Hmm...thats real simple...is there anything this simple for the "first day of the month" and "beginning of the day" ?

Re: Timestamp for beginning of the week?

Posted: Fri Sep 05, 2008 10:30 am
by andyhoneycutt
first day of the month:

Code: Select all

$month = date('m',time());
$year = date('Y',time());
$first_day_timestamp = strtotime("$month/01/$year");
start of today:

Code: Select all

$start_of_day = strtotime("Today");
Those timestamps are the very beginning of each day (e.g. 2008-09-01 00:00:00).

-Andy