Home > Backend Development > PHP Tutorial > php get the previous day's date for a given date

php get the previous day's date for a given date

巴扎黑
Release: 2016-11-22 10:50:04
Original
1341 people have browsed it

 /**
     * 
     * 获取给定日期的前一天
     * @param string $date
     * @return string $yesterday
     */
    public function getYesterday($date)
    {
        if(empty($date)) 
        {
            $yesterday = date("Y-m-d",strtotime("-1 day"));
        }else{
            $arr = explode('-', $date);
            $year = $arr[0];
            $month = $arr[1];
            $day = $arr[2];
            $unixtime = mktime(0,0,0,$month,$day,$year)-86400;
            $yesterday = date('Y-m-d',$unixtime);
        }
        
        return $yesterday;
    }
Copy after login


Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template