In PHP, you can use the "date('Y-m-d',strtotime(date))" statement to remove hours, minutes and seconds. The date() function is used to format a date or time and format the timestamp into a more readable date and time.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php time removes hours and minutes Seconds
<?php date('Y-m-d',strtotime(日期)) ?>
Related introduction:
The date() function in PHP is used to format date or time.
PHP Date() function formats a timestamp into a more readable date and time. date(format,timestamp)
Parameter description
format is required. Specifies the format of the timestamp.
timestamp Optional. Specify timestamp. The default is the current time and date.
Note: A timestamp is a sequence of characters that represents the date and event when a specific event occurred.
Get a simple date
The format parameters of the date() function are required, and they specify how to format the date or time.
Here are some characters commonly used for dates:
d - represents the day of the month (01-31)
m - represents the month (01-12)
Y - represents the year (four digits)
1 - represents the week
Other characters, such as "/", "." or "-" can also be inserted into the characters to add other formatting.
The following example uses three different methods to format today's date:
Example
<?php echo "今天是 " . date("Y/m/d") . ""; echo "今天是 " . date("Y.m.d") . ""; echo "今天是 " . date("Y-m-d") . ""; ?>
Recommendation: "2021 PHP interview questions summary ( Collection)》《php video tutorial》
The above is the detailed content of How to use date to remove hours, minutes and seconds in php. For more information, please follow other related articles on the PHP Chinese website!