Faqts : Business : Programming : Shopping For You : PHP : Function Libraries : Date and Time

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

19 of 21 people (90%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I find out what the date of the last monday was without year/month concerns?

May 31st, 2000 09:11
Nathan Wallace, Bill Pargeter, Dave Mitchell, Richard Lynch


The following _should_ determine the date of the last Monday (or today, 
if today's Monday):

    $MonDate = mktime(0,0,0,
                  (int)date("m"),
                  (int)date("j") - (((int)date("w") + 6) % 7),
                  (int)date("Y"));

The principle is to use the 'day of week' to offset the 'day of month' 
and let mktime() do the rest.

You might prefer to try this:

    $now = time();
    while (date('D', $now) != 'Mon'){
      $now -= 60*60*24;
    }
    echo date("D m/d/Y", $now);