I see excellent answers, so there is no need to repeat here, so I would like to offer some tips:
I would recommend using an integer Unix Timestamp value instead of a human-readable date format for internal time processing, and then use the PHP date() function to convert the timestamp value to a human-readable date format for display by the user. Here is a rough example of how this should be done:
// Get unix timestamp in seconds $current_time = date(); // Or if you need millisecond precision // Get unix timestamp in milliseconds $current_time = microtime(true);
Then use $current_time as needed in your application (save, add or subtract, etc.), and then when you need to display the date value for your users, you can use date() to specify the desired date format:
// Display a human-readable date format echo date('dm-Y', $current_time);
Thus, you will avoid the headache associated with date formats, conversions and time zones, since your dates will be in a standardized format (Unix Timestamp), which is compact, independent of the time zone (always in UTC) and widely supported in programming languages ββand Databases
Achraf Almouloudi Apr 24 2018-12-12T00: 00Z
source share