English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP date() Function Usage and Examples

PHP Date & Time Functions Manual

The date() function formats a local date/time

Definition and Usage

 Returns a string representing the integer timestamp formatted according to the given format string. If no timestamp is given, the local current time is used. In other words, timestamp is optional, and the default value is time().

Syntax

date($format, $timestamp)

Parameter

NumberParameters and Description
1

format (required)

This is a format string that specifies the format you want to use for the output date string.

2

timestamp (optional)

This is an integer value representing the timestamp of the required date

Return Value

The PHP date() function returns the current local time in the specified format/Date.

PHP version

This function was first introduced in PHP version4introduced and can be used in all higher versions.

Online Example

Try the following demonstration ofdate()Function Usage-

<?php
   $date = date("Y-m-d H:i:s");
   print("Date: ",$date);
?>
Test to see‹/›

Output Result

Date: 2020-07-30 13:51:04

Online Example

You can escape characters in the date format as shown below-

<?php
   $date = date("jS F l \t");
   print("Date: ",$date);
?>
Test to see‹/›

Output Result

Date: 18the May Monday

Online Example

The following examples demonstrate how to call it by passing a timestamp parameterdate()Function-

<?php
   $ts = 1022555568;
   $date = date("Y-m-d H:i:s, $ts);
   print($date);
?>
Test to see‹/›

Output Result

2002-05-28 03:12:48

Online Example

<?php
   date_default_timezone_set('UTC');
   
   echo date("l");
   echo "\n";
   
   echo date('l dS of F Y h:i:s A');
?>
Test to see‹/›

This produces the following result-

Monday
Monday 05the  of December 2016 10:27:13 AM