close[x]


PHP

PHP-Home PHP-Environment Setup PHP-Syntax PHP-Run PHP in XAMPP PHP-Variable PHP-Comment PHP-Datatype PHP-String PHP-Operators PHP-Decision PHP-loop PHP-Get/Post PHP-Do While loop PHP-While loop PHP-For loop PHP-Foreach loop PHP-Array PHP-Multidimensional Arrays PHP-Associative Arrays PHP-Indexed Arrays PHP-Function PHP-Cookies. PHP-Session PHP-File upload PHP-Email PHP-Data & Time PHP-Include & Require PHP-Error PHP-File I/O PHP-Read File PHP-Write File PHP-Append & Delete File PHP-Filter PHP-Form Validation PHP-MySQl PHP-XML PHP-AJAX



learncodehere.com




PHP - Date and Time

PHP - Date

The PHP date() function is used to format a date and/or a time.

Syntax : Date()


 date(format,timestamp)

Here is the description for each parameters.

  • format : Specifies the format of the timestamp
  • timestame : optional, specifies a timestamp. Default is the current date and time
  • The required format parameter of the date() function specifies how to format the date (or time).

    Here are some characters that are commonly used for dates:

  • d - Represents the day of the month
  • m - Represents a month
  • Y- Represents a year
  • l (lowercase 'L') - Represents the day of the week

  • Example : Data()

    
        <?php
    echo "Today is " . date("Y-m-d") . "<br>";
    echo "Today is " . date("Y/m/d") . "<br>";
    echo "Today is " . date("Y.m.d") . "<br>";
    echo "Today is " . date("l");
    echo "Today is " . date("Y");
        ?>

    It will produce the following result −

    Result

    
    Today is 2020-05-28
    Today is 2020/05/28
    Today is 2020.05.28
    Today is Thursday
    Today is 2020 


    PHP - Time

    The PHP date() function is used to format a time.

    Here are some characters that are commonly used

  • H - 24-hour format of an hour
  • h - 12-hour format of an hour
  • i - Minutes
  • s - Seconds
  • a - Lowercase Ante meridiem and Post meridiem (am or pm)
  • Example : Data() for Time

    
        <?php
    echo "The Time is " . date("h:i:sa") . "<br>";
    echo "The Time is " . date("h") . "<br>";
    echo "The Time is " . date("i") . "<br>";
    echo "The Time is " . date("s"). "<br>";
    echo "The Time is " . date("a");
        ?>

    It will produce the following result −

    Result

    
    The Time is 07:45:06am
    The Time is 07
    The Time is 45
    The Time is 06
    The Time is am