Home >Backend Development >PHP Tutorial >Is there a function for subtracting dates in php_PHP Tutorial

Is there a function for subtracting dates in php_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:52:431038browse

Direct subtraction is incorrect, you need to do it like this:
**Get the current date and time
In Unix, time is expressed by calculating the elapsed time since 0:00 on January 1, 1970 The number of seconds, this is called the UNIX timestamp (Unix Epoch).
If we have a piece of code like this:
echo time();
?>
will return the value 958905820
The time at this time is May 2000 At 12:43 on the 21st.
Pretty good, you might say. When this doesn't help me at all, or only a little. In PHP, all date processing functions must use the timestamp value returned by time(). At the same time, since PHP uses the same timestamp value in both Unix and Windows systems, this allows you to port it between different systems without modifying the code. Another benefit is that the time() function returns an integer, which you can store in the database as an integer field or a text field without having to use a special date/time field.
Now that you have a basic understanding of Unix timestamp values, let’s show you what they are used for.

Change the way date is displayed - the display format of date and time
PHP provides two methods to convert Unix timestamp value into useful data. The first is the date() function. This function takes two parameters - the first string is used to set the format you wish to return, and the second is the Unix timestamp value.
The format string uses some simple special formatting characters to display the date and time in the format you want to see. Suppose you want the date to be displayed in the format "18h01 Sunday 21 May".
We need to use a special formatting character for each part of the string, which you can find from the date and time function library in the PHP manual. There are a lot of such special formatting characters. They represent the day of the week, the English name of the month, the year represented by 2 or 4 digits, whether it is morning (AM) or afternoon (PM) and others. The special characters we need for this example are:
'H' - the hour in the 24-hour clock
'i' - the minute
'l' - the full English name of the day of the week
'd' - The day of this month
'F' - the full English name of the month
So our format string is "Hhi l d F", and the PHP code is:
echo date ("Hhi l d F" ,time());
?>
When we execute this code, we find that the result we get is:
180609 Sunday 21 May
Like this The result looks a little strange. Let's check the PHP manual again. It turns out that 'h' represents the hour in the 12-hour clock. This once again proves the truth: "The computer only does what you tell it to do, not what you want it to do." We have two options. The first is to use the escape character "" before h:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632465.htmlTechArticleDirect subtraction is incorrect, you need to do it like this: **Get the current date and time in Unix , the time is expressed by calculating the number of seconds that have passed since 0:00 on January 1, 1970, which is called...
Statement:
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