Jump to content

[SOLVED] Working out the date - beginning of this week - beginning of last month


andrewgarn

Recommended Posts

Right the requirements for my website i'm making are finding the date:

 

<> at the beginning of this week (last monday or today if its a monday today)

<> at the beginning of last week (monday)

 

<> beginning of this month - (1st of month)

<> beginning of last month - (1st of month)

 

I can get todays date by doing:

 

$yesterday = date("Y-m-d", strtotime("-1  days"));

 

but i'm not sure about what to do for the rest, any ideas?

 

Link to comment
Share on other sites

See it this helps:

<?php
$tmp = array();
$tmp[] = 'Today ' . date('Y-m-d') . ' is a ' . date('l');
$begweek = (date('l') == 'Monday')?date('Y-m-d'):date('Y-m-d',strtotime('last monday'));
$tmp[] = 'The beginning of the week was ' . $begweek;
$tmp[] = 'The beginning of last week was ' . date('Y-m-d',strtotime('-2 monday'));
$tmp[] = 'The start of this month was ' . date('Y-m-01') . ', a ' . date('l',strtotime(date('Y-m-01')));
$tmp[] = 'The start of last month was ' . date('Y-m-01',strtotime('last month')) . ', a '. date('l',strtotime(date('Y-m-01',strtotime('last month'))));
echo implode("<br>\n",$tmp);
?>

 

Ken

Link to comment
Share on other sites

See it this helps:

<?php
$tmp = array();
$tmp[] = 'Today ' . date('Y-m-d') . ' is a ' . date('l');
$begweek = (date('l') == 'Monday')?date('Y-m-d'):date('Y-m-d',strtotime('last monday'));
$tmp[] = 'The beginning of the week was ' . $begweek;
$tmp[] = 'The beginning of last week was ' . date('Y-m-d',strtotime('-2 monday'));
$tmp[] = 'The start of this month was ' . date('Y-m-01') . ', a ' . date('l',strtotime(date('Y-m-01')));
$tmp[] = 'The start of last month was ' . date('Y-m-01',strtotime('last month')) . ', a '. date('l',strtotime(date('Y-m-01',strtotime('last month'))));
echo implode("<br>\n",$tmp);
?>

 

Ken

 

Thank you, does exactly what i need, should be able to work out any further I need :)

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.