Kamis, 05 Maret 2015

Manage Date and Time using php


The example below outputs the dates for the next six Saturdays:

Example:
<?php
$startdate = strtotime("Saturday");
$enddate = strtotime("+6 weeks",$startdate);
while ($startdate < $enddate) {
echo date("M d", $startdate),"<br>";
$startdate = strtotime("+1 week", $startdate);
}
?>
The example below outputs the number of days until 4th of July:
Example:
<?php
$d1=strtotime("July 04");
$d2=ceil(($d1-time())/60/60/24);
echo "There are " . days until 4th of July.";
?>
Create a Date With PHP mktime()
The optional timestamp parameter in the date() function specifies a timestamp. If you do not specify a timestamp, the current date and time will be used (as shown in the examples above). The Unix timestamp contains the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.
Syntax:
mktime(hour,minute,second,month,day,year)
The example below creates a date and time from a number of parameters in the mktime() function:
Example:
<?php
$d=mktime(11, 14, 54, 8, 12, 2014);
echo "Created date is " .

Tidak ada komentar:

Posting Komentar