PHP Development Notes-day/week operations Common Date Acquisition Method _php Tutorial

Source: Internet
Author: User
Tags echo date
Monday
echo Date (' y-m-d ', (Time ()-((Date (' W ') ==0?7:date (' W ') ')-1) *24*3600)); W is the number form of the day of the week, where 0 is Sunday

This Sunday

echo Date (' y-m-d ', (Time () + (7-(' W ') ==0?7:date (' W ')) *24*3600)); Also use W to calculate the number of days related to the current and Sunday

Last Monday

echo Date (' y-m-d ', Strtotime ('-1 Monday ', Time ())); No matter what day it is, -1 Monday is the last effective week

Last Sunday

echo Date (' y-m-d ', Strtotime ('-1 Sunday ', Time ())); Last valid Sunday, same applies to other weeks

This month

echo Date (' y-m-d ', strtotime (date (' Y-m ', Time ()). ' -01 00:00:00 ')); Generate directly with Strtotime

Last day of the month

echo Date (' y-m-d ', strtotime (date (' Y-m ', Time ()). ' -'. Date (' t ', Time ()). ' 00:00:00 ')); T is the number of days in the month, 28-31 days

Last month

echo Date (' y-m-d ', Strtotime ('-1 month ', Strtotime (date (' Y-m ', Time ()). ' -01 00:00:00 ')); This month, the direct strtotime minus one months.

Last day of last month

echo Date (' y-m-d ', strtotime (date (' Y-m ', Time ()). ' -01 00:00:00 ')-86400); Minus one day this month is the last of the month.

Reprinted from http://hi.baidu.com/panez/item/bc88803f487955f2a884289d

http://www.bkjia.com/PHPjc/776509.html www.bkjia.com true http://www.bkjia.com/PHPjc/776509.html techarticle this Monday echo date (' y-m-d ', (Time ()-((Date (' W ') ==0?7:date (' W ')-1) *24*3600)),//w is the number of days of the week, here 0 is Sunday this Sunday echo date (' Y-m-d ', (Time () + (7-(the date (' W ') ==0?7 ...

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