Timestamp for beginning of the week?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pjjacobs
Forum Newbie
Posts: 2
Joined: Wed Sep 03, 2008 6:23 am

Timestamp for beginning of the week?

Post 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:
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Timestamp for beginning of the week?

Post by andyhoneycutt »

Code: Select all

$last_monday = strtotime("last Monday");
pjjacobs
Forum Newbie
Posts: 2
Joined: Wed Sep 03, 2008 6:23 am

Re: Timestamp for beginning of the week?

Post by pjjacobs »

Hmm...thats real simple...is there anything this simple for the "first day of the month" and "beginning of the day" ?
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Timestamp for beginning of the week?

Post 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
Post Reply