[ create a new paste ] login | about

Link: http://codepad.org/S2NhrU2Z    [ raw code | output | fork ]

PHP, pasted on Aug 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
function last_monday($date) {
    if (!is_numeric($date))
        $date = strtotime($date);
    if (date('w', $date) == 1)
        return $date;
    elseif (date('w', $date) == 0)
        return strtotime(
            'next monday',
             $date
        );
    else
        return strtotime(
            'last monday',
             $date
        );
}

echo date('m/d/y', last_monday('8/14/2012'));

?>


Output:
1
08/13/12


Create a new paste based on this one


Comments: