PHP gets last week, week, month, month, quarter, last quarter time method

Source: Internet
Author: User
Tags echo date
This article is about PHP get last week, this week, last month, this month, this quarter, the last quarter time method, has a certain reference value, now share to everyone, the need for friends can refer to



During the development process, the usual date processing functions, timestamp processing functions, etc., are explained as follows: <?phpecho date (' y-m-d h:i:s ', Time ());//Run result (month and day seconds, "-" interval): 2014-09-12 06:28:32echo Date (' y-m-d ', Time ());//Run result (month and day, "-" interval): 2014-09-12echo date (' y-m-d ', strtotime (' y-m-d ', Time ()-86400));// Run result (day of the year before the current date, "-" interval): 2014-09-11echo date (' Ymd ', Time ());//Run result (month and day, no interval): 20140912echo date (' m-d ', Time ());//Run result (Month day, "-" interval): 09-12echo str_replace ("-", "Month", Date (' m-d ', Time ()-date (' W ', Time ()) *86400). " Day ";//Run result (month, kanji display interval): September 12 Echo Date (' W ', Time ());//Run result (day of the week): 5echo times ();//Run result (seconds of current datetime): 1410503809echo Strtotime (Date (' y-m-d ', Time ()));//Run result (current date seconds, specific to day): 1410503809echo date (' y-m-d ', strtotime (date (' y-m-d ', Time ())) -date (' W ', Strtotime (date (' y-m-d ', Time ())))///Run result (the date of the natural week to which the current date belongs is Sunday, specific to day, "-" interval): 2014-09-07



PHP gets today's start timestamp and end timestamp $begintoday=mktime (0,0,0,date (' m '), date (' d '), date (' Y ')), $endToday =mktime (0,0,0,date (' m '), Date (' d ') +1,date (' y ')) -1;//php gets the start timestamp and end timestamp of yesterday $beginyesterday=mktime (0,0,0,date (' m '), date (' d ') -1,date (' Y ')); Endyesterday=mktime (0,0,0,date (' m '), date (' d '), date (' Y ')) -1;//php get last week's start timestamp and end timestamp $beginlastweek=mktime (0,0,0, Date (' m '), date (' d ')-date (' W ') +1-7,date (' Y ')), $endLastweek =mktime (23,59,59,date (' m '), date (' d ')-date (' W ') +7-7, Date (' Y '));//php gets the starting timestamp and end timestamp of the month $beginthismonth=mktime (0,0,0,date (' m '), 1,date (' y ')); $endThismonth =mktime ( 23,59,59,date (' m '), date (' t '), date (' Y '));


<?php/**date 2015-04-11 * Author http://www.lai18.com **/echo date ("Ymd", Strtotime ("Now")), "\ n";    echo Date ("Ymd", Strtotime ("1 week Monday")), "\ n";    echo Date ("Ymd", Strtotime ("1 week Sunday")), "\ n";    echo Date ("Ymd", Strtotime ("+0 Week Monday")), "\ n";    echo Date ("Ymd", Strtotime ("+0 Week Sunday")), "\ n";    echo "********* months:";    echo Date (' n ');    echo "********* Week of the week:";    Echo Date ("W");    echo "********* Days of the Month:";    echo Date ("T");    echo "*********";    Echo ' <br> last week start time:<br> ';    echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M"), Date ("D")-date ("W") +1-7,date ("Y")), "\ n";    echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), Date ("D")-date ("W") +7-7,date ("Y")), "\ n";    Echo ' <br> this week start time:<br> ';    echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M"), Date ("D")-date ("W") +1,date ("Y")), "\ n";    echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), Date ("D")-date ("W") +7,date ("Y")), "\ n";    Echo ' <br> last month start time:<br> '; Echo Date ("Y-m-d h:i:s ", mktime (0, 0, 0,date (" M ") -1,1,date (" Y "))," \ n ";    echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), 0,date ("Y")), "\ n";    Echo ' <br> month start time:<br> ';    echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M"), 1,date ("Y")), "\ n";    echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), Date ("T"), Date ("Y")), "\ n";    $season = Ceil ((date (' n '))/3);//month of the first quarter echo ' <br> this quarter start time:<br> ';    echo Date (' y-m-d h:i:s ', mktime (0, 0, 0, $season *3-3+1,1,date (' Y ')), "\ n"; echo Date (' y-m-d h:i:s ', Mktime (23,59,59, $season *3,date (' t ', mktime (0, 0, 0, $season *3,1,date ("y"))), date (' Y ')), "\ n"    ;    $season = Ceil ((date (' n '))/3) -1;//last quarter was the first quarter of ECHO ' <br> last quarter start time:<br> ';    echo Date (' y-m-d h:i:s ', mktime (0, 0, 0, $season *3-3+1,1,date (' Y ')), "\ n"; echo Date (' y-m-d h:i:s ', Mktime (23,59,59, $season *3,date (' t ', mktime (0, 0, 0, $season *3,1,date ("y"))), date (' Y ')), "\ n" ;? >
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.