PHP Date and Time formats

date("format", timestamp) Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.
PHP
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
<?php echo date("F j, Y, g:i a"); // May 15, 2011, 9:35 am echo date("m.d.y"); // 05.15.11 echo date("j, n, Y"); // 15, 5, 2011 echo date("Ymd"); // 20110515 echo date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 15th day. echo date("D M j G:i:s T Y"); // Thu May 15 9:35:39 CEST 2011 echo date('H:m:s \m \i\s\ \m\o\n\t\h'); // 09:05:39 m is month echo date("H:i:s"); // 09:35:39 echo date("Y-m-d H:i:s"); // 2014-05-15 09:35:39 (the MySQL DATETIME format) ?>

Predefined Date and Time Format

As of PHP 5.1.1+ these predefined date & time constants are available in PHP. These constants are intended to comply with various date formats.
PHP
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
<?php echo gmdate(DATE_W3C, time()); // 2014-08-12T05:26:33+00:00 echo gmdate(DATE_ATOM, time()); // 2011-08-12T05:21:58+00:00 echo gmdate(DATE_COOKIE, time()); // Tuesday, 12-Aug-11 05:22:28 GMT echo gmdate(DATE_ISO8601, time()); // 2011-08-12T05:22:56+0000 echo gmdate(DATE_RFC822, time()); // Tue, 12 Aug 11 05:23:16 +0000 echo gmdate(DATE_RFC2822, time()); // Tue, 12 Aug 2011 05:25:24 +0000 echo gmdate(DATE_RFC1123, time()); // Tue, 12 Aug 2011 05:25:24 +0000 echo gmdate(DATE_RFC850, time()); // Tuesday, 12-Aug-11 05:23:54 GMT echo gmdate(DATE_RFC1036, time()); // Tue, 12 Aug 11 05:25:24 +0000 echo gmdate(DATE_RSS, time()); // Tue, 12 Aug 2011 05:26:11 +0000 ?>
    New question is currently disabled!