Download
    Interview Question     &Answer
Main Menu
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:
2018-04-242018/04/24Apr 24, 2018April 24, 2018Tue Apr 24, 2018Tuesday April 24, 2018Tuesday April 24, 2018, 04:34:51Tuesday April 24, 2018, 04:34 AM

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:
yesterday was 2018-04-23

Example- 2
<?php
echo "1 week form today was ".date("Y-m-d", strtotime("-1 weeks"));
?>
OutPut:
1 week form today was 2018-04-17

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:
2000: Yes
2001: No
2002: No
2003: No
2004: Yes
2005: No
2006: No
2007: No
2008: Yes
2009: No
2010: No
2011: No
2012: Yes
2013: No
2014: No



IT  Projects Links
M-Tech Thesis
Php Project
Java Project
Asp.Net Project
Android Project
Vb .Net Project
Html Project

------------------------------- Electronics  Project
Networking
Embedded system
Telecom
Robotics
CCNA
------------------------------- Latest IT  News


Copyright 2010-2015    shwetankeducation.com
Privacy & Terms