Speed up development with full-stack environments for every branch.

Learn More

How to display dates in different formats [PHP]

1415 Runs 11494 Views 3830 Copies
Saved

Saved

dipesh.parmar 55

dipesh.parmar
published 4 years ago

<div style="margin-left:50px;">
  <h2>Displaying dates in different formats.</h2>
  <?php
    /*
      syntax :
      date ( $format , $timestamp = time() )
      as you can see timestamp is optional,
      if no timestamp is specified then it will take current timestamp.
      where time() return current unix timestamp.
    */
    
    /*
      below is example of different format,
      and here is little description of them.
      Y : A full numeric representation of a year, 4 digits
      m : Numeric representation of a month, with leading zeros
      d : Day of the month, 2 digits with leading zeros
      M : A short textual representation of a month, three letters
      F : A full textual representation of a month, such as January or March
    */
    
    echo date("Y-m-d");
    echo "<br/>";
  	echo date("Y/m/d");
    echo "<br/>";
  	echo date("M d, Y");
    echo "<br/>";
  	echo date("F d, Y");
    echo "<br/>";
  	echo date("D M d, Y");
    echo "<br/>";
  	echo date("l F d, Y");
    echo "<br/>";
  	echo date("l F d, Y, h:i:s");
    echo "<br/>";
  	echo date("l F d, Y, h:i A");
  ?>
  <p>
    for more date formats read
    <a href="http://www.php.net/manual/en/function.date.php" target="_blank">PHP Date Format</a>
  </p>
</div>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).