Home >Backend Development >PHP Tutorial >PHP gets the first and last day of this week and this month
2, PHP DATE gets the first day of the month And the last day! echo date('Y-m-01',time()).'----'.date('Y-m-t',time()) 3, PHP time function: the first day of the next month on a given date, the first day of the current month Code: function GetPurMonth($date){//Get the first and last day of the previous month for the specified date.
The problem arises. For example, to get the first day, use (date('m',$time)-1); what if you want to get the previous month of a given date. Should we directly subtract 2? What if the given date is January. Will it eventually become date('Y-m-01', strtotime('2012--1-01'))????? This is obviously a wrong time format. Therefore, this function is not suitable for extended use. Query the PHP function library and find a function mktime(); mktime() Definition and usage The mktime() function returns the Unix timestamp of a date. The argument always represents a GMT date, so is_dst has no effect on the result. The parameters can be left empty in order from right to left, and the empty parameters will be set to the corresponding current GMT value. grammar mktime(hour,minute,second,month,day,year,is_dst) Example: The mktime() function is useful for date operations and validation. It can automatically correct out-of-bounds input; What does it mean. Automatically correct out-of-bounds input. Opponent. This is what we want. Let’s look at an example below
to output the dates 2 months before January 1, 2012. That is October 1, 2011. 1970-01-01 2011-10-01 in conclusion: The first function has an error. The time with timestamp 0 is shown. And the second function gives us the time we want. |