Php Date Function

PHP Date@ Shwetank

Script   Date Function in php
PHP has nice built in date function which allows you to display dates in human readable formats

Example With Date Format

echo date(“Y-m-d”);
echo date(“Y/m/d”);
echo date(“M d, Y”);
echo date(“F d, Y”);
echo date(“D M d, Y”);
echo date(“l F d, Y”);
echo date(“l F d, Y, h:i:s”);

echo date(“l F d, Y, h:i A”);


Try It

Script   Timestamp in php
timestamp parameter we can do things like say find exactly what date or day it was yesterday or a week ago or what date it will be 1 month from today
Using the PHP strtotime function.
Using the PHP mktime function.
strtotime – Convert any English textual datetime description into a Unix timestamp.
mktime – Get Unix timestamp for a date.

Example- 1
echo “yesterday was “.date(“Y-m-d”, strtotime(“-1 days”));

Try It

Example- 2
echo “1 week form today was “.date(“Y-m-d”, strtotime(“-1 weeks”));

try it

Example- 3 Find Which Year In Leap
for($i = 2000; $i < 2011; $i++)
  echo $i, ‘: ‘, (date(‘L’, strtotime(“$i-01-01”)) ? ‘Yes’ : ‘No’), ‘


Try it