Apply for Zend Framework Certification Training

Corephp




< First How to sanitize user input in PHP >



PHP date() Function
 
Hi viewers!
Many times, while developing a PHP application, we need to display the current date. PHP provides a built-in date() function that makes it easy to display the date in different formats.
Syntax
date(format, timestamp);
format – Specifies how the date should be displayed.
timestamp – Optional. Specifies a particular date and time. If omitted, the current date and time are used.
Common Date Format Characters
Character Description Example
d Day of the month (01–31) 16
m Month (01–12) 08
Y Year in four digits 2026
l Full name of the day of the week Sunday
Example
<?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");
?>
Output
Today is 2026/08/16
Today is 2026.08.16
Today is 2026-08-16
Today is Sunday
Here, we are using the same date() function with different format characters to display the current date in different formats.
Note: The output depends on the server's configured date and time zone.

< First How to sanitize user input in PHP >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top