Is there a way to find the day of the week in php with a particular date.

I don't mean

date('D', $timestamp);

I mean if I was to supply a date like 2010-10-21 it would return "third thursday".

Accepted Answer

Not directly, you need a helper function for that:

function literalDate($timestamp) {
    $timestamp = is_numeric($timestamp) ? $timestamp : strtotime($timestamp);
    $weekday   = date('l', $timestamp);
    $month     = date('M', $timestamp);   
    $ord       = 0;

    while(date('M', ($timestamp = strtotime('-1 week', $timestamp))) == $month) {
        $ord++;
    }

    $lit = array('first', 'second', 'third', 'fourth', 'fifth');
    return strtolower($lit[$ord].' '.$weekday);
}

echo literalDate('2010-10-21'); // outputs "third thursday"

Working example:

http://codepad.org/PTWUocx9

Written by Tatu Ulmanen
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki