Take the 2-minute tour ×

Which PHP function can return the current date/time?

share|improve this question
add comment

13 Answers

The time would go by your server time. An easy workaround for this is to manually set the timezone before the date() or time() functions are called to.

I'm in Melbourne, Australia so I have something like this:


Or another example is LA - US:


You can also see what timezone the server is currently in via:


So something like:

$timezone = date_default_timezone_get();
echo "The current server timezone is: " . $timezone;

So the short answer for your question would be:

// Change the line below to your timezone!

Then all the times would be to the timezone you just set :)

share|improve this answer
The call to time() is redundant, date() will automatically use the current time. –  too much php Jan 23 '09 at 0:26
Thanks! I was wondering how to change the time zone on the date() function :) –  Nathan Oct 3 '11 at 6:25
Which one is PST? –  oneofakind Aug 6 '13 at 2:29
@oneofakind America/Los_Angeles –  MysteryMeatMonster Sep 4 '13 at 0:34
OP never asked about timezone. A simpler and more correct answer would simply show server time. –  AyexeM Feb 21 at 16:38
add comment
    // Simply:

    // Or:
    $date = date('Y/m/d H:i:s');

    // This would return the date in the following formats respectively:
    $date = '2012-03-06 17:33:07';
    // Or
    $date = '2012/03/06 17:33:07';

     * This time is based on the default server time zone.
     * If you want the date in a different time zone,
     * say if you come from Nairobi, Kenya like I do, you can set
     * the time zone to Nairobi as shown below.


    // Then call the date functions
    // Or

    // date_default_timezone_set() function is however
    // supported by PHP version 5.1.0 or above.

For a time-zone reference, see List of Supported Timezones.

share|improve this answer
add comment

You can either use the $_SERVER['REQUEST_TIME'] variable (available since PHP 5.1.0) or the time() function to get the current Unix timestamp.

share|improve this answer
add comment

PHP's time() returns a current unix timestamp. With this, you can use the date() function to format it to your needs.

$date = date('Format String', time());

As Paolo mentioned in the comments, the second argument is redundant. The following snippet is equivalent to the one above:

$date = date('Format String');
share|improve this answer
the 2nd argument of the date function is assumed to be time() if left empty. –  Paolo Bergantino Jul 7 '09 at 7:10
add comment

Since PHP 5.2.0 you can do this as well (of course if you prefer OOP):

$now = new DateTime();
echo $now->format('Y-m-d H:i:s');    // MySQL datetime format
echo $now->getTimestamp();           // Unix Timestamp -- Since PHP 5.3

And to specify the timezone:

$now = new DateTime(null, new DateTimeZone('America/New_York'));
$now->setTimezone(new DateTimeZone('Europe/London'));    // Another way
echo $now->getTimezone();
share|improve this answer
getTimstamp() is apparently available on PHP 5.3.0 or higher,not 5.2.0 –  Kama Jan 4 at 3:08
@Kama Thanks for the heads up, I've updated with the correction :) –  Mahdi Jan 4 at 10:53
add comment

You can use both the $_SERVER['REQUEST_TIME'] variable or the time()function. Both of these return a Unix timestamp.

Most of the time these two solutions will yield the exact same Unix Timestamp. The difference between these is that $_SERVER['REQUEST_TIME'] returns the time stamp of the most recent server request and time() returns the current time. This may create minor differences in accuracy depending on your application, but for most cases both of these solutions should suffice.

Based on your example code above, you are going to want to format this information once you obtain the Unix Timestamp. An unformatted Unix timestamp looks like this...

Unix Timestamp: 1232659628

So in order to get something that will work, you can use the date() function to format it.

A good reference for ways to use the date() function is located in the PHP Manual Pages, here...


As an example, the following code returns a date that looks like this -

01/22/2009 04:35:00 pm

echo date("m/d/Y h:i:s a", time());
share|improve this answer
add comment

Reference: Here's a link

This can be more reliable than simply adding or subtracting the number of seconds in a day or a month to a timestamp because of daylight saving time.

The PHP code

// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone

$today = date('h-i-s, j-m-y, it is w Day');     // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // it is the 10th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:18 m is month
$today = date("H:i:s");                         // 17:16:18
$today = date("Y-m-d H:i:s");                   // 2001-03-10 17:16:18 (the MySQL DATETIME format)
share|improve this answer
i liked this ans –  arslan Jan 25 at 16:41
Thank you for this clear answer –  Midway Media Jan 29 at 15:07
add comment
 $date = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
 echo $date->format('d-m-Y H:i:s');


 //Also get am/pm in datetime:
 echo $date->format('d-m-Y H:i:s a'); // output 30-12-2013 10:16:15 am

For the date format, PHP date() Function is useful.

share|improve this answer
add comment
echo "<b>".date('l\, F jS\, Y ')."</b>";

Prints like this

Sunday, December 9th, 2012

share|improve this answer
add comment

works, but how also to know if it's EST, PST?

share|improve this answer
What I mean is the time comes back EST when I'm PST... but why? Is it the server time and the server is EST? Can I get users time? Their server may be another time zone, no? –  Mike Jan 22 '09 at 22:38
Look into the manual: docs.php.net/manual/en/function.date.php –  Gumbo Jan 22 '09 at 22:39
The date function is the time of your server, either check it, or temporarily set it /w PHP before you run date. –  TravisO Jan 22 '09 at 22:48
thanks, my service must not be up to date with php because O works for GMT but not P or "e" time zone... thanks!! –  Mike Jan 22 '09 at 22:54
This $date = date('m/d/Y h:i:s a', time()); gets the server date but still doesn't get me the user date. This is showing me at EST when I'm at PST. I want to get the date the user sends the form and like me their server may be in a different time zone. –  Mike Jan 22 '09 at 22:57
show 2 more comments

I found that the simplest way of getting the current time in PHP is something like this.

//Prints out something like 10:00am Just be sure to set your timezone correctly.
$TIME = date('G:ia'); 
share|improve this answer
add comment

According to the article How to Get Current Datetime (NOW) with PHP, there are two common ways to get the current date. To get current datetime (now) with PHP, you can use the date class with any PHP version, or better the datetime class with PHP >= 5.2.

Various date format expressions are available here.

Example using date

This expression will return NOW in format Y-m-d H:i:s.


Example using datetime class


    $dt = new DateTime();
share|improve this answer
add comment

If you want a different timescale, please use:

$tomorrow  = mktime(0, 0, 0, date("m")  , date("d")+1, date("Y"));
$lastmonth = mktime(0, 0, 0, date("m")-1, date("d"),   date("Y"));
$nextyear  = mktime(0, 0, 0, date("m"),   date("d"),   date("Y")+1);

echo date("Y/m/d H:i:s");
share|improve this answer
What do you mean by "timescale"? –  Peter Mortensen Feb 2 at 10:43
"timezone", probably. –  Saneem Mar 11 at 15:26
add comment

protected by animuson Jan 20 at 7:50
