check if given date time is of today or yesterday php

Solutions on MaxInterview for check if given date time is of today or yesterday php by the best coders in the world

showing results for - "check if given date time is of today or yesterday php"
Ana
15 Sep 2020
1function getRangeDateString($timestamp) {
2    if ($timestamp) {
3        $currentTime=strtotime('today');
4        // Reset time to 00:00:00
5        $timestamp=strtotime(date('Y-m-d 00:00:00',$timestamp));
6        $days=round(($timestamp-$currentTime)/86400);
7        switch($days) {
8            case '0';
9                return 'Today';
10                break;
11            case '-1';
12                return 'Yesterday';
13                break;
14            case '-2';
15                return 'Day before yesterday';
16                break;
17            case '1';
18                return 'Tomorrow';
19                break;
20            case '2';
21                return 'Day after tomorrow';
22                break;
23            default:
24                if ($days > 0) {
25                    return 'In '.$days.' days';
26                } else {
27                    return ($days*-1).' days ago';
28                }
29                break;
30        }
31    }
32}
33