VOOZH about

URL: https://www.geeksforgeeks.org/php/how-to-get-the-current-date-and-time-in-php/

⇱ How to get the current Date and Time in PHP ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to get the current Date and Time in PHP ?

Last Updated : 26 Sep, 2024

To get the current date and time in PHP, use the date() function, which formats UNIX timestamps into a human-readable format. It converts timestamps, measured in seconds since January 1, 1970, into a more understandable representation for users.

Syntax:  

date('d-m-y h:i:s');

Parameters:  The date() has different parameters. Each parameter represents some meaningful unit. 

  • d: It represents the day of the month which has two digits with leading zeros (01 or 31)
  • m: It represents month in numbers with leading zeros (01 or 1)
  • y: It represents a year in two digits (08 or 14).
  • h: It represents the hour of the day in two digits with leading zeros (01 or 1)
  • I: It represents the minute in the current time zone.
  • s: It represents the number of seconds in the current timezone.

Example 1: In this example we displays the current date and time by storing it in the $myDate variable using the date() function and then printing it in the format day-month-year hours:minutes:seconds.

Output:

Current date and time is :03-01-21 04:49:52

Example 2: The following demonstrates other date() functions format which can be used by the developer as per the need.

Output:

👁 Image
Comment