Technology Programming

How to Find a Current Date in PHP

    Date function

    • 1). Open a text editor and start a new file.

    • 2). Determine how you want the date to be formatted. The default in the US is date/month/year. This will be represented in PHP as "d/m/Y" with "d" representing a two-digit day of the month, "m" representing a two-digit month, and "Y" representing a four-digit year.

    • 3). Type the following into the text editor file:

      <?php

      $date = date("d/m/Y");

      echo $date;

      ?>

    • 4). Save the file in your computer's server root folder, making sure to use the ".php" file extension.

    • 5). Open a web browser window and navigate to the file.

    DateTime class

    • 1). Open a text editor and start a new file.

    • 2). Determine how you want the date to be formatted. The default is date/month/year, or "d/m/Y" in php.

    • 3). Type the following into the text editor file:

      <?php

      $date = new DateTime();

      echo $date->format("d/m/Y");

      ?>

    • 4). Save the file in your computer's server root folder, making sure to use the ".php" file extension.

    • 5). Open a web browser window and navigate to the file.



Leave a reply