Time always matters. A site that does not control time and does not use it continuously does not have the right to life, but it definitely does not belong to fully-functional modern Internet resources.
PHP functions for working with time
In PHP, time and date are represented by a set of functions sufficient to work without restrictions, and the ability to bring time and date to a single base. The developer can always get a timestamp for recording (tracking) events and performing date calculations.
There is no need to write your own code that controls (calculates) the number of days in a month, leap year, day of the week, month name, etc. You can work on a project and rely entirely on PHP's ability to work with this parameter.
In principle, two functions (getTimeStamp, GetDate) are enough to solve any problem when working with date and / or time. But a sophisticated developer can use other features.
Essentially: in PHP, timestamp is a kind of numerical label, which every second takes on a new numerical meaning (value). Historically, this number is the number of seconds that have passed since midnight on January 1, 1970 .
Objective Reality and Timestamp Value
There have always been many epoch-making dates in programming. Just as any decent programmer remembers the date of his very first program, so the Unixoid family celebrates the beginning of his era.
Moreover, the idea due to the implementation method is limited in time. You can use it only until January 19, 2038. At 03:14:08 the number of seconds elapsed since 01/01/1970 will reach 2 ^ 31 (2147483648), which makes this number negative. They say that using not a 32-bit, but a 64-bit variable for storing time will postpone the problem for another 300 billion years: programmers love bugs like jokes, especially after 2000.
Period calculation and date determination
The time represented by a prime number makes it possible to have simple arithmetic.
An interesting idea is to use this arithmetic as keys for records and / or unique events. Using a timestamp in a PHP program in conjunction with a user or visitor identifier as a key, you donβt have to worry about its uniqueness and donβt waste time on it.
Convert back to date and time
The time () function directly gives a numerical knowledge of the timestamp. Regardless of how and when the PHP date to timestamp conversion was performed, it can be cast back to any convenient representation by the date (format [, timestamp] function). If the second parameter is absent, the current date and / or time will be displayed. The format value can be any, the language tools provide all the necessary options for localizing and formatting the date and time.
Numerical storage is always preferable to symbolic, and in addition, the ability to sort is greatly simplified. Also important is the ability to use simple mathematics to control time periods and calculate dates.
It is hardly possible to make a mistake in such calculations; the result of any calculations is always interpreted correctly in the natural date / time format.
Time localization
And although in PHP date to timestamp and subsequent work with numbers seem convenient and ideal in the modern world, there are still plenty of reasons to store and use the date in its natural, and sometimes exclusively, national format.
The power of modern computers is sufficient, databases efficiently present and store information, sampling is fast, and the right algorithm makes working with real dates perfectly acceptable.
The times of assembly and saving on bytes are long gone. There are not many tasks that require the correct machine code and compact presentation of data; most of the projects are related to practical social spheres, where the date should be presented in the proper natural format.
With all this, manipulating data in PHP, timestamp does not lose its practical value and deserves to be in the arsenal of a qualified developer.
Current time
The general rule of all PHP time functions is: current time = timestamp. All dates set manually by the user or developer, as a rule, are data: the beginning or end of the period, date of birth, employment, etc. Temporary data is usually entered through an interactive calendar. In particular, this is a jQuery datapicker, which allows you to enter the date and / or time directly in the browser environment, on the site page.
Datapicker and similar developments are executed not only fully functional. They also provide the ability to customize the localization of both the date / time format and the names of the months, days of the week, and symbols for separating date and time elements.
A developer can execute date to timestamp in PHP to check, compare, and perform arithmetic operations.
At the same time, the data entered by the user (visitor) is not a PHP timestamp function , the purpose of which is different. However, it is precisely this specificity of PHP functions that allows the developer to control the input of time and date data by the user.