PHP Time Calculation related issues summary, PHP related issues summary _php tutorial

Source: Internet
Author: User
Tags echo date getting started with php

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 ...

  • Related Article

    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.