PHP Date - Code

PHP Print Previous Next PHP Time


PHP date() function is used to get date time or format date,time.

Syntax


date(format, timestamp)

Filename: php / date.php


Code
<?php
// php date
echo date('d/m/Y');
?>

Running Step.


Type Url - https://localhost/php/date.php

Date Format

Filename: php / date-format.php


Code
<?php
// php date
echo "Today Date in YYYY/MM/DD Format: ".date('Y/m/d');
echo "
"; echo "Today Date in YYYY-MM-DD Format: ".date('Y-m-d'); echo "
"; echo "Today Date in YYYY.MM.DD Format: ".date('Y.m.d'); ?>

Running Step.


Type Url - https://localhost/php/date-format.php

Filename: php / date-format1.php


Code
<?php
// php date
echo "Today Date in DD/MM/YYYY Format: ".date('d/m/Y');
echo "
"; echo "Today Date in DD-MM-YYYY Format: ".date('d-m-Y'); echo "
"; echo "Today Date in DD.MM.YYYY Format: ".date('d.m.Y'); ?>

Running Step.


Type Url - https://localhost/php/date-format1.php

Get Year


Year parameter have two variation give below.

1.Y - Capital Y Repersents year in 4 digits YYYY Ex: 2019.

2.y - Small y Repersents last 2 digits of year YY Ex: 19.

Filename: php / year.php


Code
<?php
// PHP Year
echo "Current Year is ".date('Y'); 
echo "
"; echo "Current Year last 2 digit is ".date('y'); echo "
"; ?>

Running Step.


Type Url - https://localhost/php/year.php

Get Month


Month parameter have two variation give below.

1.M - Capital M Repersents first three letter of month in text Ex: Jan to Dec

2.m - Small m Repersents month in numeric value with leading zero Ex: 01 or 12..

Filename: php / month.php


Code
<?php
// PHP Month
echo "Current Month is ".date('M'); 
echo "
"; echo "Current Month first three letter is ".date('m'); echo "
"; ?>

Running Step.


Type Url - https://localhost/php/month.php

Get Day


Month parameter have two variation give below.

1.D - Capital D Repersents first three letter of day of the week in text Ex: Mon to Sun

2.d - Small d Repersents day of the month in numeric value with leading zero Ex: 01 or 31..

Filename: php / day.php


Code
<?php
// PHP Month
echo "Today Day in text is ".date('D'); 
echo "
"; echo "Today Day in numeric value is ".date('d'); echo "
"; ?>

Running Step.


Type Url - https://localhost/php/day.php


Tags: PHP Date PHP Code Programming Language


Was this helpful ?

Related Code