PHP Time Calculation related issues summary _php skills

Source: Internet
Author: User
Tags echo date php introduction

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.