get yesterday date in php

61

yesterday php -

date('F j, Y',strtotime("-1 days"));

php yesterday -

$yesterday = new DateTime('yesterday');
echo $yesterday->format('Y-m-d');

get yesterday date in php -

echo date("Y-m-d", strtotime("yesterday")); 

yesterday php -

date("F j, Y", time() - 86400);

check if given date time is of today or yesterday php -

function getRangeDateString($timestamp) {
    if ($timestamp) {
        $currentTime=strtotime('today');
        // Reset time to 00:00:00
        $timestamp=strtotime(date('Y-m-d 00:00:00',$timestamp));
        $days=round(($timestamp-$currentTime)/86400);
        switch($days) {
            case '0';
                return 'Today';
                break;
            case '-1';
                return 'Yesterday';
                break;
            case '-2';
                return 'Day before yesterday';
                break;
            case '1';
                return 'Tomorrow';
                break;
            case '2';
                return 'Day after tomorrow';
                break;
            default:
                if ($days > 0) {
                    return 'In '.$days.' days';
                } else {
                    return ($days*-1).' days ago';
                }
                break;
        }
    }
}

Comments

Submit
0 Comments