Monday, May 9, 2016

WDP - PHP Date & Time

PHP Date and Time

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

SYNTAX
date(format,timestamp)

**Note:
format - Required. Specifies the format of the timestamp
timestamp - Optional. Specifies a timestamp. Default is the current date and time


Here are some characters that are commonly used for dates:
  • d - Represents the day of the month (01 to 31)
  • m - Represents a month (01 to 12)
  • Y - Represents a year (in four digits)
  • l (lowercase 'L') - Represents the day of the week

SAMPLE CODE & OUTPUT

<?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 2016/05/10

Today is 2016.05.10
Today is 2016-05-10

No comments:

Post a Comment