--------------------------------------------------------------------------------------------------------------------------
Prepared By : Uday Shah (HOD - IT)
Contact No : +91 7600044051
E-mail : rupareleducation@gmail.com
PHP Date & Time
function
No
|
Name
|
Description
|
1
|
date()
|
It returns a
current system date & time according to the given format.
Syntax:
date(string format)
Ex:
date(“m.d.y”);
|
2
|
getdate()
|
It returns
current date & time information in associative array format like
Seconds - Numeric
representation of seconds 0 to 59
Minutes - Numeric representation of minutes 0 to 59
Hours - Numeric representation of hours 0 to 23
Mday - Numeric representation of the day of month 1
to 31
Wday - Numeric representation of the day of week 0(Sunday)
to 6(Saturday)
Mon - Numeric representation of month 1 to 12
Year - A full numeric representation of the day of
the year-4
Digits
1999 or 2003
Yday - Numeric representation of the day of the year 0 to 365
Weekday - A full textual representation of the day
of the week
Sunday to Saturday
Month - A full
textual representation of the month January
to
December
|
3
|
checkdate()
|
It returns true
if the given date is valid otherwise it returns false.
Syntax:
checkdate(int month,int day,int year)
Ex:
checkdate(12,31,2000);
|
4
|
Time()
|
It returns the
current unix time stamp which is measured in the number of seconds since unix
time stamp.
Syntax: time():
Ex:
<?php
nextweek=time()
+ (7 * 24 * 60 * 60);
echo ‘now: ‘.date(‘Y-m-d’);
echo ‘next
week: ‘.date(‘Y-m-d’,$nextweek);
?>
|
5
|
mktime()
|
It returns the
unix time stamp corresponding to the argument given.
Syntax: int
mktime([int hour[,int minute[,int second[,int month[,int day[,int
year]]]]]]);
Ex: date[‘m-d-y’
mktime(0,0,0,1,1,1998);
|
6
|
date_add()
|
The date_add()
function adds some days, months, years, hours, minutes, and seconds to a
date.
Syntax
date_add(object,interval);
Example
Add 40 days to the 15th of March, 2015:
<?php
$date=date_create("2015-03-15"); date_add($date,date_interval_create_from_date_string("40 days")); echo date_format($date,"Y-m-d"); ?> |
7
|
date_create ()
|
The date_create () function returns a new DateTime
object.
Syntax
date_create(time,timezone);
Example
Return a new DateTime object, and then format the
date:
<?php
$date=date_create("2013-03-15"); echo date_format($date,"Y/m/d"); ?> |
8
|
date_format()
|
The date_format() function returns a date formatted
according to the specified format.
Syntax
date_format(object,format);
Example
Return a new DateTime object, and then format the
date:
<?php
$date=date_create("2013-03-15"); echo date_format($date,"Y/m/d H:i:s"); ?> |
9
|
gmdate()
|
The gmdate() function formats a GMT/UTC date and
time, and returns the formatted date string.
(GMT:Greenwich Mean Time or UTC: Universal Time Coordinated)
Syntax
gmdate(format,timestamp);
Example
Format a GMT/UTC date and time and return the
formatted date strings:
<?php
// Prints the day echo gmdate("l") . "<br>"; // Prints the day, date, month, year, time, AM or PM echo gmdate("l jS \of F Y h:i:s A"); ?>
d - The day of the month (from 01 to 31)
D - A textual representation of a day
(three letters)
j - The day of the month without leading
zeros (1 to 31)
l (lowercase 'L') - A full textual
representation of a day
N - The ISO-8601 numeric representation
of a day (1 for Monday, 7 for Sunday)
S - The English ordinal suffix for the
day of the month (2 characters st, nd, rd or th. Works well with j)
w - A numeric representation of the day (0
for Sunday, 6 for Saturday)
z - The day of the year (from 0 through
365)
W - The ISO-8601 week number of year
(weeks starting on Monday)
F - A full textual representation of a
month (January through December)
m - A numeric representation of a month
(from 01 to 12)
M - A short textual representation of a
month (three letters)
n - A numeric representation of a month,
without leading zeros (1 to 12)
t - The number of days in the given month
L - Whether it's a leap year (1 if it is
a leap year, 0 otherwise)
o - The ISO-8601 year number
Y - A four digit representation of a year
y - A two digit representation of a year
a - Lowercase am or pm
A - Uppercase AM
or PM
|
10
|
localtime()
|
The localtime() function returns the local time.
Syntax
localtime(timestamp,is_assoc);
Example
<?php
print_r(localtime()); echo "<br><br>"; print_r(localtime(time(),true)); ?> |
11
|
strftime()
|
The strftime() function formats a local time and/or
date according to local settings.
Syntax
strftime(format,timestamp);
Example
<?php
echo(strftime("%B %d %Y, %X %Z",mktime(20,0,0,12,31,98))."<br>"); //setlocale(LC_ALL,"hu_HU.UTF8"); echo(strftime("%Y. %B %d. %A. %X %Z")); ?>
%a - abbreviated
weekday name
%A - full
weekday name
%b - abbreviated
month name
%B - full month
name
%c - preferred
date and time representation
%d - day of the
month (01 to 31)
%D - same as
%m/%d/%y
%e - day of the
month (1 to 31)
%g - like %G,
but without the century
%H - hour, using
a 24-hour clock (00 to 23)
%I - hour, using
a 12-hour clock (01 to 12)
%m - month (01
to 12)
%M – minute
%n - newline
character
%r - time in
a.m. and p.m. notation
%R - time in 24
hour notation
%S - second
%t - tab
character
%T - current
time, equal to %H:%M:%S
%u - weekday as
a number (1 to 7), Monday=1.
%X- Preferred
time representation for current local without date
%y- Year as a
decimal number within range 00 to 99
%Z- time zone or name or abbreviation
|
12
|
strptime()
|
The strptime() function parses a time/date generated
with strftime().
Note: This function is not
implemented on Windows platforms!
Syntax
strptime(date,format);
Example
Parse a time/date generated with strftime():
<?php
$format="%d/%m/%Y %H:%M:%S"; $strf=strftime($format); echo("$strf"); print_r(strptime($strf,$format)); ?> |
13
|
strtotime()
|
The strtotime() function parses an English textual
datetime into a Unix
Timestamp. (the number of seconds since January 1
1970).
Syntax
strtotime(time,now);
Example
<?php
echo(strtotime("now") . "<br>"); echo(strtotime("14 July 2016")."<br>"); echo(strtotime("+5 hours")."<br>");
?>
|
14
|
gettimeofday()
|
The gettimeofday() function returns the current time
from the system call like,
“sec”-seconds
“usec”-microseconds
Syntax
gettimeofday(return_float);
Example
<?php
print_r(gettimeofday());
?>
|
15
|
Setdate()
|
It is used to set the date.
Syntax
date setdate(year,month,day)
Example
<?php
echo setdate(2016,07,14);
?>
|
:: Best Of Luck ::
https://myshopprime.com/uday.shah3/shop