Php obtains the timestamp of the current month, the beginning of last month, and the end of last month.

Source: Internet
Author: User

Php obtains the timestamp of the current month, the beginning of last month, and the end of last month.

This example describes how to obtain the timestamp of the current month, the beginning of last month, and the end of last month by using php. We will share this with you for your reference. The details are as follows:

Current month

<? Php $ thismonth = date ('M'); $ thisyear = date ('y'); $ startDay = $ thisyear. '-'. $ thismonth. '-1'; $ endDay = $ thisyear. '-'. $ thismonth. '-'. date ('T', strtotime ($ startDay); $ B _time = strtotime ($ startDay); // The timestamp $ e_time = strtotime ($ endDay) at the beginning of the current month ); // The end timestamp of the current month

Last month

<? Php $ thismonth = date ('M'); $ thisyear = date ('y'); if ($ thismonth = 1) {$ lastmonth = 12; $ lastyear = $ thisyear-1;} else {$ lastmonth = $ thismonth-1; $ lastyear = $ thisyear;} $ lastStartDay = $ lastyear. '-'. $ lastmonth. '-1'; $ lastEndDay = $ lastyear. '-'. $ lastmonth. '-'. date ('T', strtotime ($ lastStartDay); $ B _time = strtotime ($ lastStartDay); // The timestamp at the beginning of last month $ e_time = strtotime ($ lastEndDay ); // last month Timestamp

The key here is t in the date function, which is used to obtain the number of days in the current month, 28 days, 29 days, 30 days, 31 days. The number of days at the end of the month.

PS: This site also provides a Unix timestamp conversion tool, including the timestamp operation methods in various common languages, for your reference:

Unix timestamp Conversion Tool:
Http://tools.jb51.net/code/unixtime

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.