Strtotime (String $ time [, int $ now]) int strtotime (string $time [, int $now] This function expects to get a date format containing US English and will attempt to parse it into a Unix timestamp ( How many seconds since January 1, 1970 00:00:00 Monday that format), relative to the time stamp provided now, or the current time if not provided now
This function uses the TZ environment variable (if any) to calculate the timestamp, and since PHP 5.1.0 has an easier way to determine the time zone of all/datetime functions used, this process is explained on a page of the Date_default_timezone_get () function.
Parsing the string, in PHP 5.0.0, is not allowed in microseconds, since PHP 5.0.0 they are allowed, but ignored.
Now which is the time stamp used as the calculated cardinality relative to the date.
Return value: Returns a timestamp in the successful return, otherwise false, before the PHP 5.1.0, this function will return a failure-1.
Now let's take a look at the strtotime character conversion to the time function instance, the code is as follows:
<?php
function
function Nextweeksday ($date _begin, $nbrweek)
{
$nextweek =array ();
for ($i = 1; $i <= $nbrweek; $i + +) {//week in one year of coursewww.phpfensi.com
$nextweek [$i]=date (' d d M Y ', strtotime (' + '. $i. ' Week ', $date _begin));
}
return $nextweek;
}
End Function
Example of a Select date
Var
$date _begin = strtotime (' 06-05-2010 '); D Day Month year-like function format.
$nbrweek = 52;
Call function
$result =nextweeksday ($date _begin, $nbrweek);
Preview
for ($i = 1; $i <= $nbrweek; $i + +) {
Echo ' <br>-$result [$i];
}
?>
<?php
$str = ' not good ';
Previous to PHP 5.1.0 you would compare with-1, instead of false
if ($timestamp = Strtotime ($str)) = = = = False) {
echo "The string ($STR) is bogus";
} else {
echo "$str = =". Date (' l DS o F Y h:i:s A ', $timestamp);
}
?>
<?php
Echo Strtotime ("Now"), "";
Echo Strtotime ("Ten September 2000"), "";
Echo strtotime ("+1 Day"), "";
Echo strtotime ("+1 Week"), "";
Echo strtotime ("+1 Week 2 days 4 hours 2 Seconds"), "";
Echo Strtotime ("next Thursday"), "";
Echo Strtotime ("Last Monday"), "";
?>
This is a fast function calculation during the year, "Working days", "workdays" are those that do not have weekends, no holidays specified in the $ array of holidays, the instance code is as follows:
function Get_working_days ($to _date) {
$holidays = Array (
1 = Array (10),//2011 ...
2-= Array (11),
3 = = Array (21),//... 2011
4 = Array (29,30),//2010 ...
5 = Array (3,4,5),
6 = = Array (),
7-= Array (19),
8 = Array (11,12,13),
9 = Array (20,23),
Array (11),
One by one and array (3,23),
Array (23)//... 2010
);
For ($to _date, $w = 0, $i = 0, $x = time (), $x < $to _date, $i + +, $x = Strtotime ("+ $i Day") {
if (Date ("n", $x) < 6 &! In_array (Date ("J", $x), $holidays [Date ("n", $x)])) $w ++;//Open Source code phpfensi.com
}
return $w;
}
Usage:
Echo get_working_days (Strtotime ("2011-01-08"));