PHP Date@ Shwetank education.com
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
<?php
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”);
?>
OutPut:
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
<?php
echo “yesterday was “.date(“Y-m-d”, strtotime(“-1 days”));
?>
Output:
Try It
Example- 2
<?php
echo “1 week form today was “.date(“Y-m-d”, strtotime(“-1 weeks”));
?>
OutPut:
try it
Example- 3 Find Which Year In Leap
<?php
for($i = 2000; $i < 2011; $i++)
{
echo $i, ‘: ‘, (date(‘L’, strtotime(“$i-01-01”)) ? ‘Yes’ : ‘No’), ‘
‘;
}
?>
OutPut:
Try it