Get a Simple Date with PHP date() Function. $dateTime-> format ('Y')); $diff = $dateTime-> diff ($limitDate); $soma = 1; if ($dateTime-> format ('L') && $diff-> invert) { $soma = 2; } return ( (int) $dateTime-> format ('z')) + $soma;} Here are some the date-related formatting characters that are commonly used in format string: The parts of the date can be separated by inserting other characters, like hyphens (-), dots (. Super basic function, takes no parameters and returns the current date. All Rights Reserved. PHP User Defined Functions. The date_create() function accepts a date time string and time zone (optional) as parameters and, creates a DateTime object accordingly. PHP Date and Time Functions. The date() function is used to display the date and time in a human-readable format. If no date and time is provided, the timestamp for the current date and time is returned. The easiest way to convert a date from a format (here yyyy-mm-dd) to another. It is mostly used in logging the information when the system is performing any operations on the server. PHP current date might be displayed at … The provided results based on the timezone settings in the php.ini file. This function was first introduced in PHP Version 5.3.0 and, works with all the later versions. Note that while creating a function its name should start with keyword functionand all the PHP code should be put inside { and } braces as shown in the following example below − This will display following result − The system stores the date and time in the timestamp format. The strtotime() function accepts an English datetime description and turns it into a timestamp. The following section contains a list of PHP date and time functions along with a brief description. Return a new DateTime object (with a given timezone), and then format the date and time: