---
title: "PHP Date() Function"  
description: "PHP date () function is used for retrieving  the current date and time from the server, you can used ‘date’ function to set the format of date and tim"  
author: "Anonymous User"  
published: 2011-09-12  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/726/php-date-function  
category: "php"  
tags: ["php"]  
reading_time: 3 minutes  

---

# PHP Date() Function

PHP date () [function](https://www.mindstick.com/articles/43970/purchase-suitable-wedding-dresses-for-your-wedding-function) is used for retrieving the [current date](https://www.mindstick.com/forum/323/find-the-day-name-and-month-name-from-current-date) and time from the server, you can used ‘date’ function to set the format of date and time with many different ways.\

The PHP date () function formats a [timestamp](https://www.mindstick.com/interview/626/what-is-the-physical-storage-length-of-each-of-the-following-db2-data-types-date-time-timestamp) to a more readable date and time (where timestamp is a sequence of [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters), denoting the date and/or time at which a certain event occurred).

##### The basic syntax of ‘date’ function is given follows.

##### Syntax:

date (Format, Timestamp) ;

Where [parameters](https://www.mindstick.com/articles/87/passing-parameters-in-c-sharp) are,

· **Format –** Specifies the format of timestamp, it is [required](https://yourviews.mindstick.com/view/81031/vigilence-required-during-corona-pandemic) parameter in date function.

· **Timestamp –** It is an [optional parameter](https://www.mindstick.com/interview/1310/how-do-i-simulate-optional-parameters-to-com-calls) which specifies the timestamp, default is date and time.

There are lots of characters used in PHP to modify format of date function. Here I am described some characters which is widely used in formatting of date function. Let’s see the brief description about these.

· **‘d’ :** [Character](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) ‘d’ represents the day of the month.

· **‘m’ :** Character ‘m’ represents the month of year.

· **‘y’ :** Character ‘y’ represents the year.

##### Let’s we have an example, how to format date function in PHP.

##### Example:

```
<html>        <head>               <title> Date Function  </title>        </head>               <body>               <?php                     //  Set defaulttimezoneused by all date time function                         date_default_timezone_set ("Asia/Calcutta");                        //  print date in differentformats                          echo "date format is y-m-d  : ".date("y-m-d")."</br>";                          echo "date format is y.m.d  : ".date("y.m.d")."</br>";                          echo "date format is y/m/d  : ".date("y/m/d");               ?>        </body></html>
```

##### Output:

![PHP Date() Function](https://www.mindstick.com/mindstickarticle/ae23accb-6def-4578-b623-1425f5c29967/images/aee9145d-df94-41bb-aab5-6fd54b0a6c23.png)

##### Adding Timestamp with date( ) function:

The optional timestamp parameter in the date () function specifies a timestamp. If you do not specify a timestamp, the current date and time will be used. “The ‘mktime()’ function returns the Unix timestamp for a date”. PHP time stamp is a numeric value in seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.

##### Let’s we have an example, how to add timestamp with date function.

##### Syntax:

mktime( Hour, Minute, Second, Month ,Day, Year, is_dst);

Basically, mktime() function is useful for doing date arithmetic and validation.

Where all parameters are defined as:

· Hour: It is optional parameter which specifies the hour.

· Minute: It is optional parameter which specifies the minute.

· Second: It is optional parameter which specifies the second.

· Month: It is optional parameter which specifies the month of year.

· Day: It is optional parameter which specifies the day of month.

· Year: It is optional parameter which specifies the current year.

· is_dst: It is also optional parameter. This parameter can be set to 1 if the time is during daylight savings time (DST), 0 if it is not, or -1 (the default) if it is unknown whether the time is within daylight savings time or not.

**Note:** This parameter became deprecated in PHP 5. The new time zone handling features should be used instead.

##### Example:

```
<html>     <head>                <title>Date Timestamp</title>     </head>     <body>         <?php         // put yourcode here         date_default_timezone_set ("Asia/Calcutta");         $tomorrow = mktime (0,0,0,  date("m"),date("d")+1,date("Y"));         echo "Tomorrow date is : ".date("Y/m/d",$tomorrow);         ?>     </body></html>
```

##### Output:

![PHP Date() Function](https://www.mindstick.com/mindstickarticle/ae23accb-6def-4578-b623-1425f5c29967/images/c0780330-426e-4662-988a-a841e30d1660.png)

\

---

Original Source: https://www.mindstick.com/articles/726/php-date-function

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
