This article summarizes the problems related to PHP time calculation. Share to everyone for your reference, specific as follows:
1. PHP get three months ago date
<?php header ("content-type:text/html; Charset=utf-8 ");? >
<?php
$s _sdate=date ("y-m-d");//Current time
$moth _day=90;//month (convert to days)
$s _edate=date ("y-m-d", Strtotime ($s _sdate)-$moth _day*84600));
echo $moth _day. " The date before is ". $s _edate;
? >
2.30 days after the date of calculation
You can use strtotime PHP to provide a super simple way to do what would have been dozens of lines of code.
First convert a date to a Unix timestamp
$t = time (); Current timestamp
$t = strtotime ("+30 days", $t);//30 day timestamp
echo date ("y-m-d", $t);//Format Date
3. Convert time stamp for 2nd period ... and subtract.
$t 1 = strtotime ("2009-08-19");
$t 2 = strtotime ("2009-08-20");
$t = $t 2-$t 1; Second
echo (int) ($t/86400) in Days of difference
4. Determine if this is the week
$date = "2008-12-08";
if (Iscurrentweeks ($date)) {
echo $date. " Is this week ";
} else {
echo $date. " Not this week ";
}
function Iscurrentweeks ($d) {return
(date ("W", Strtotime ($d)) ==date ("W", Strtotime ("Now"));
}
More interested in PHP related content readers can view the site topics: "PHP date and Time usage summary", "PHP string (String) Usage summary", "PHP Array" Operation Techniques Encyclopedia, "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP Operations Office Document Tips summary (including word,excel,access,ppt)", "PHP Introduction to Object-oriented Programming", "Php+mysql Database Operations Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.