The implementation of PHP’s year, month, and day, PHP’s date addition and subtraction calculation strtotimeDate implementation date plus year, month, and day
In many bills and logics involving the date of the month,It is very necessary to use the two functions of strtotime Date in PHP to handle date-related calculations. Simply relying on timestamps for processing will become very passive. Especially 2 is only 28 days , There are differences between big moons and small moons. Let’s get acquainted with the commonly used PHP date addition and subtraction calculation strtotime Date to realize several demos of date addition and year month day. Get the date from the start to the end of the current month, get the date from the start to the end of the previous month at the current time, get the start of the current time to the start of the next year, “get the given date (2015-05-01) add 20-day date, etc. header(“Content-Type:text/html;Charset=UTF-8”); //Get the beginning to end of the current month $sDate = date(“Y-m-01”); $eDate = date(“Y-m-d”, strtotime(“$sDate & #43;1 month -1 day”)); echo “Get the current month’s start to end year, month, day“; echo $sDate.”“; echo $eDate.”“; echo “ “; $sDate= date('Y-m-01',strtotime(date('Y',time()).'-'.(date('m' 39;,time())-1).'-01')); $eDate=date('Y-m-d',strtotime( “$sDate +1 month -1 day”)); echo “Get the start to end year, month and day of the current month“; echo $sDate.”“; echo $eDate.”“;…
PHP gets the hour, day, month, and year before and after the current time
//Get the start date of this month$begindate=date('Y-m-01' , strtotime(date(“Y-m-d”)));$enddate =date('Y-m-d', strtotime(“$begindate +1 month -1 day”));//Get the date one year ago$begindate= date('Y-m-d', strtotime(date('Y-m-01') . ' -1 year') ); $begindate = date(“Y-m-d H:i:s”, strtotime(“-1 year”));//Get the date one month ago: where the value: -1 is a variable $mothtime= date (“Y-m-d H:i:s”, strtotime(“-1 month “));//Get the starting date a few months ago: the value: -1 is a variable$begindate= date( 'Y-m-d', strtotime(date(&# 39;Y-m-01') . ' -1 month')); // Calculate the first day of this month minus one month$enddate = date('Y-m-d', strtotime(date('Y-m-01') . ' -1 day')); //Calculate the first day of the month minus one day//Get one day Previous date: its value: -1 is variable; -1 is one day ago, and so on$daytime= date(“Y-m-d H:i:s”, strtotime( span>”-1 day”));//Get the date and time one hour ago$hourtime = date(“Y-m-d H:i:s”, strtotime(“-1 hour”) ); mysql query specified time period such as 8 :00 – 17:00 The database stores two fields 800 and 1700 Get the current time, for example, 2020-12-30 12:53 Get the current minute 12:53 and convert it to 1253 1700> 1253>800
php gets the current time, and php gets the current time year, month, day, hour, minute, and second
A list of the contents of this article: 1. PHP gets the day of the week or a certain date and what time is the current time, morning It’s still in the afternoon 2. PHP gets the current server time 3. How does PHP get the current time > 4. Get the current time in php 5. How to get the current time in php? PHP get What day of the week is the day or a certain date and what time is the current time, am or pm public function index(){ $data=time(); $format=’week’; $week = date( “D”,$data); switch($week){ case “Mon”:$current = $format.”One”;break; case “Tue”:$current = $format.”Two”;break; case “Wed “:$current = $format.”Three”;break; case “Thu”:$current = $format.”Four”;break; case “Fri”: $current = $format.”Five”;break; case “Sat”:$current = $format.”Six”;break; case “Sun”:$current = $format.”Day”;break; } echo ‘Today is:’.$current;echo “ “;//Get current Whether the time is morning or afternoon // Lowercase g and h represent 12-hour clock, capital G and H represent 24-hour clock. echo “Now is”.date(“H”,$data).’point’.””; echo “Now is”.date(“G”,$ data).’point’.””; if(date(“H”,$data)=12){echo “morning”;}else{echo “afternoon”;}// return $ current;} PHP gets the current server time php gets the server time, the tool used: notepad++, The steps are as follows: The code is as follows: ?php //Taking China as…
PHP calculates age accurately to year, month, day
The example in this article describes how PHP calculates the age accurately to the year, month, and day. Share it with everyone for your reference. The details are as follows: <?php /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ class Age { /** * The calculated age is accurate to the year, month, and day * @param type $birthday * @return array */ public function calAge($birthday) { list($byear, $bmonth, $bday) = explode('-', $birthday); list($year, $month, $day) = explode('-', date('Y-m-d')); $bmOnth = intval($bmonth); $bday = intval($bday); if ($bmonth <10) { $bmOnth = '0' . $bmonth; } if ($bday $ni) { $not_birth = 1; $tmp = array($byear, $bmonth, $bday); list($byear, $bmonth, $bday) = array($year, $month, $day); list($year, $month, $day) = $tmp; list($bi, $ni) = array($ni, $bi); } $years = 0; while (($bi + 10000) getMD(array($year, $month, $day), array($byear, $bmonth, $bday)); return array(‘year’ => $years, ‘month’ => $m, ‘day’ => $d, ‘not_birth’ => $not_birth); } /** * Can only be used for calculation within one year * @param type $ymd * @param type $bymd */ public function getMD($ymd, $bymd)…