PHP Time Calculation related issues summary, PHP related issues summary
This paper summarizes the problems related to PHP time calculation. Share to everyone for your reference, as follows:
1. PHP Gets the date three months ago
<?php header ("content-type:text/html; Charset=utf-8 ");? ><?php$s_sdate=date ("y-m-d"); Current time $moth_day=90; Month (converted to days) $s _edate=date ("y-m-d", (Strtotime ($s _sdate)-$moth _day*84600); Echo $moth _day. " Before the date is ". $s _edate;? >
2. Calculation Date 30 days later
You can use strtotime PHP to provide a super-simple way to do the work that would have been dozens of lines of code.
Convert a date to a UNIX timestamp first
$t = time (); Current timestamp $t = Strtotime ("+30 days", $t); 30 days after the timestamp echo date ("y-m-d", $t); Formatted 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; seconds echo (int) ($t/86400) difference in number of days
4. Judging 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 readers interested in PHP related content can view the topic: "PHP Date and Time usage summary", "PHP String Usage Summary", "PHP array" operation skill Daquan, "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", PHP tips for working with Office documents (including WORD,EXCEL,ACCESS,PPT), PHP tutorial for object-oriented programming, getting started with Php+mysql database operations, and PHP common database operations Tips Summary
I hope this article is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1125894.html www.bkjia.com true http://www.bkjia.com/PHPjc/1125894.html techarticle PHP Time Calculation related issues summary, PHP related issues Summary This article summarizes the PHP time calculation related issues. Share to everyone for your reference, as follows: 1. PHP gets three months ago ...