当前位置:网站首页>Solution to the problem of PHP strtotime obtaining natural monthly error
Solution to the problem of PHP strtotime obtaining natural monthly error
2022-06-11 20:45:00 【The world is white_ I am the only one】
Differences in basic writing
for($i=1;$i<150;$i++){
$date = date('Y-m-d',strtotime("+{$i} day",strtotime('2022-01-25')));
echo $date.' >>> ';
// echo getNaturalMonth(-1,$date,true);
echo date('Y-m-d',strtotime('+1 month',strtotime($date)));
echo PHP_EOL;
}
Optimize the writing :
/**
* Get the next natural month date of a time
* @date 2022/5/31
* @param int $num Increase the number of months 1 Add one month -1 One month less
* @param null $date date
* @param bool $is_supplement If the current time is the last day of the current month, the new natural month will automatically return to the last day
* @return false|string|null
*/
function getNaturalMonth($num = 1,$date=null,$is_supplement = false)
{
$new_date = null;
$time = isset($date) ? strtotime($date): time();
$_time = strtotime($num.' month',$time);
$new_date = date('Y-m-d',$_time);
$new_day = date('d',$_time);
if($is_supplement == true && $new_day == date('t',$time)) { // Current date is the last day
$new_date = date('Y-m-t', strtotime('last day of ' . $num . ' month', $time));
} elseif($new_day != date('d',$time)){ // Judge whether the obtained month and day are the same as the current date
$new_date = date('Y-m-d',strtotime('last day of '.$num.' month',$time));
}
return $new_date;
}When $is_supplement = false when
2022-01-26 >>> 2022-02-26
2022-01-27 >>> 2022-02-27
2022-01-28 >>> 2022-02-28
2022-01-29 >>> 2022-02-28
2022-01-30 >>> 2022-02-28
2022-01-31 >>> 2022-02-28
2022-02-01 >>> 2022-03-01
2022-02-02 >>> 2022-03-02
2022-02-03 >>> 2022-03-03
2022-02-04 >>> 2022-03-04
2022-02-05 >>> 2022-03-05
2022-02-06 >>> 2022-03-06
2022-02-07 >>> 2022-03-07
2022-02-08 >>> 2022-03-08
2022-02-09 >>> 2022-03-09
2022-02-10 >>> 2022-03-10
2022-02-11 >>> 2022-03-11
2022-02-12 >>> 2022-03-12
2022-02-13 >>> 2022-03-13
2022-02-14 >>> 2022-03-14
2022-02-15 >>> 2022-03-15
2022-02-16 >>> 2022-03-16
2022-02-17 >>> 2022-03-17
2022-02-18 >>> 2022-03-18
2022-02-19 >>> 2022-03-19
2022-02-20 >>> 2022-03-20
2022-02-21 >>> 2022-03-21
2022-02-22 >>> 2022-03-22
2022-02-23 >>> 2022-03-23
2022-02-24 >>> 2022-03-24
2022-02-25 >>> 2022-03-25
2022-02-26 >>> 2022-03-26
2022-02-27 >>> 2022-03-27
2022-02-28 >>> 2022-03-28
2022-03-01 >>> 2022-04-01
2022-03-02 >>> 2022-04-02
2022-03-03 >>> 2022-04-03
2022-03-04 >>> 2022-04-04
2022-03-05 >>> 2022-04-05
2022-03-06 >>> 2022-04-06
2022-03-07 >>> 2022-04-07
2022-03-08 >>> 2022-04-08
2022-03-09 >>> 2022-04-09
2022-03-10 >>> 2022-04-10
2022-03-11 >>> 2022-04-11
2022-03-12 >>> 2022-04-12
2022-03-13 >>> 2022-04-13
2022-03-14 >>> 2022-04-14
2022-03-15 >>> 2022-04-15
2022-03-16 >>> 2022-04-16
2022-03-17 >>> 2022-04-17
2022-03-18 >>> 2022-04-18
2022-03-19 >>> 2022-04-19
2022-03-20 >>> 2022-04-20
2022-03-21 >>> 2022-04-21
2022-03-22 >>> 2022-04-22
2022-03-23 >>> 2022-04-23
2022-03-24 >>> 2022-04-24
2022-03-25 >>> 2022-04-25
2022-03-26 >>> 2022-04-26
2022-03-27 >>> 2022-04-27
2022-03-28 >>> 2022-04-28
2022-03-29 >>> 2022-04-29
2022-03-30 >>> 2022-04-30
2022-03-31 >>> 2022-04-30
2022-04-01 >>> 2022-05-01
2022-04-02 >>> 2022-05-02
2022-04-03 >>> 2022-05-03
2022-04-04 >>> 2022-05-04
2022-04-05 >>> 2022-05-05
2022-04-06 >>> 2022-05-06
2022-04-07 >>> 2022-05-07
2022-04-08 >>> 2022-05-08
2022-04-09 >>> 2022-05-09
2022-04-10 >>> 2022-05-10
2022-04-11 >>> 2022-05-11
2022-04-12 >>> 2022-05-12
2022-04-13 >>> 2022-05-13
2022-04-14 >>> 2022-05-14
2022-04-15 >>> 2022-05-15
2022-04-16 >>> 2022-05-16
2022-04-17 >>> 2022-05-17
2022-04-18 >>> 2022-05-18
2022-04-19 >>> 2022-05-19
2022-04-20 >>> 2022-05-20
2022-04-21 >>> 2022-05-21
2022-04-22 >>> 2022-05-22
2022-04-23 >>> 2022-05-23
2022-04-24 >>> 2022-05-24
2022-04-25 >>> 2022-05-25
2022-04-26 >>> 2022-05-26
2022-04-27 >>> 2022-05-27
2022-04-28 >>> 2022-05-28
2022-04-29 >>> 2022-05-29
2022-04-30 >>> 2022-05-30
2022-05-01 >>> 2022-06-01
When $is_supplement =true when
2022-01-26 >>> 2022-02-26
2022-01-27 >>> 2022-02-27
2022-01-28 >>> 2022-02-28
2022-01-29 >>> 2022-02-28
2022-01-30 >>> 2022-02-28
2022-01-31 >>> 2022-02-28
2022-02-01 >>> 2022-03-01
2022-02-02 >>> 2022-03-02
2022-02-03 >>> 2022-03-03
2022-02-04 >>> 2022-03-04
2022-02-05 >>> 2022-03-05
2022-02-06 >>> 2022-03-06
2022-02-07 >>> 2022-03-07
2022-02-08 >>> 2022-03-08
2022-02-09 >>> 2022-03-09
2022-02-10 >>> 2022-03-10
2022-02-11 >>> 2022-03-11
2022-02-12 >>> 2022-03-12
2022-02-13 >>> 2022-03-13
2022-02-14 >>> 2022-03-14
2022-02-15 >>> 2022-03-15
2022-02-16 >>> 2022-03-16
2022-02-17 >>> 2022-03-17
2022-02-18 >>> 2022-03-18
2022-02-19 >>> 2022-03-19
2022-02-20 >>> 2022-03-20
2022-02-21 >>> 2022-03-21
2022-02-22 >>> 2022-03-22
2022-02-23 >>> 2022-03-23
2022-02-24 >>> 2022-03-24
2022-02-25 >>> 2022-03-25
2022-02-26 >>> 2022-03-26
2022-02-27 >>> 2022-03-27
2022-02-28 >>> 2022-03-31
2022-03-01 >>> 2022-04-01
2022-03-02 >>> 2022-04-02
2022-03-03 >>> 2022-04-03
2022-03-04 >>> 2022-04-04
2022-03-05 >>> 2022-04-05
2022-03-06 >>> 2022-04-06
2022-03-07 >>> 2022-04-07
2022-03-08 >>> 2022-04-08
2022-03-09 >>> 2022-04-09
2022-03-10 >>> 2022-04-10
2022-03-11 >>> 2022-04-11
2022-03-12 >>> 2022-04-12
2022-03-13 >>> 2022-04-13
2022-03-14 >>> 2022-04-14
2022-03-15 >>> 2022-04-15
2022-03-16 >>> 2022-04-16
2022-03-17 >>> 2022-04-17
2022-03-18 >>> 2022-04-18
2022-03-19 >>> 2022-04-19
2022-03-20 >>> 2022-04-20
2022-03-21 >>> 2022-04-21
2022-03-22 >>> 2022-04-22
2022-03-23 >>> 2022-04-23
2022-03-24 >>> 2022-04-24
2022-03-25 >>> 2022-04-25
2022-03-26 >>> 2022-04-26
2022-03-27 >>> 2022-04-27
2022-03-28 >>> 2022-04-28
2022-03-29 >>> 2022-04-29
2022-03-30 >>> 2022-04-30
2022-03-31 >>> 2022-04-30
2022-04-01 >>> 2022-05-01
2022-04-02 >>> 2022-05-02
边栏推荐
- Systematically study the recommendation system from a global perspective to improve competitiveness in actual combat (Chapter 8)
- MySQL installation free configuration tutorial under Windows mysql-5.6.51-winx64 Zip version
- Deploy website traffic statistics background based on Tencent cloud lightweight application server and umami
- Calculation of Zeno paradox
- moderlarts第二次作业
- [file upload vulnerability 04] server side mime detection and bypass experiment (based on upload-labs-2 shooting range)
- 黑圆圈显示实现
- Windows icon display exception resolution. The desktop icon is abnormal, the start menu icon is abnormal, and the taskbar icon is abnormal. Icon cache location.
- 2022-2028 current situation and future development trend of global and Chinese thermocouple belt Market
- 2022-2028 global and Chinese thermopile array module market status and future development trend
猜你喜欢

【数据可视化】Apache Superset 1.2.0教程 (三)—— 图表功能详解

周刊02|不瞒你说,我其实是MIT的学生

Première formation sur les largeurs modernes

26. timer

In unity, opencv and QT are used to create a plugin (I)

Why should I use iwarp, roce V2, nvme of and other protocols for 100g network transmission

8 r subset
![[file upload vulnerability 04] server side mime detection and bypass experiment (based on upload-labs-2 shooting range)](/img/b8/521ca4bb8931afab9a3a4d0b015125.jpg)
[file upload vulnerability 04] server side mime detection and bypass experiment (based on upload-labs-2 shooting range)

使用flask框架写挡板

The principle that the picture of QQ Post Bar changes when it is opened
随机推荐
php pcntl_fork 创建多个子进程解析
Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
unity package manager starting server stuck(Unity啟動卡在starting server,然後報錯)
A Mechanics-Informed Artificial Neural Network Approach in Data-Driven Constitutive Modeling 学习
【计算机推免】哈尔滨工业大学物联网与泛在智能研究中心面向全国高校推免生招收2023级研究生(硕、博、直博生)
【数据可视化】使用 Apache Superset 可视化 ClickHouse 数据
[file upload vulnerability 04] server side mime detection and bypass experiment (based on upload-labs-2 shooting range)
Pyqt5 technical part - cause of the problem that setting the top of the window does not take effect. Setwindowflags() does not take effect after setting the parameters. Solution
26. 定时器
ORA-01089 ORA-19809 ORA-19815 超过了恢复文件的限制
Oracle case: ora-00600: internal error code, arguments: [4187]
新品发布:国产单电口千兆网卡正式量产!
产品资讯|PoE网卡家族集体亮相,机器视觉完美搭档!
2022-2028 global and Chinese thermal ionization isotope mass spectrometer (TIMS) market status and future development trend
Première formation sur les largeurs modernes
R 16 basic exercises
Black circle display implementation
Windows icon display exception resolution. The desktop icon is abnormal, the start menu icon is abnormal, and the taskbar icon is abnormal. Icon cache location.
Toolbar替换ActionBar后Title不显示
7905 和TL431 负电压稳压电路 - 相对于电源正极的稳压和浮地电路