dump(date('Y-m-d', strtotime('2018-10-1 +1 day')));

dump(date('Y-m-d', strtotime('2018-10-1 +1 week')));

dump(date('Y-m-d', strtotime('2018-10-1 +1 month')));

dump(date('Y-m-d', strtotime('2018-10-1 +1 year')));

dump(date('Y-m-d', strtotime('2018-10-1 -1 day')));

dump(date('Y-m-d', strtotime('2018-10-1 -1 week')));

dump(date('Y-m-d', strtotime('2018-10-1 -1 month')));

dump(date('Y-m-d', strtotime('2018-10-1 -1 year')));

同理,把2018-10-1换成变量,就可以做很多事了!

ps 由于每个月份的天数不一样 +/- 1 month 特殊日期会有误差

//获取上一个月日期方法

public function getBeforeMonthDate($currentDate)
{
$currentMonthDay = date('t', strtotime($currentDate));
$currentDay = date('d', strtotime($currentDate));
$yearMonth = date('Y-m', strtotime($currentDate));
$beforeMonth = date('Y-m-d', strtotime("$yearMonth -1 month"));
$beforeMonthDay = date('t', strtotime($beforeMonth));
if ($beforeMonthDay < $currentMonthDay && $beforeMonthDay < $currentDay) {
$beforeDate = date("Y-m-d", strtotime("last day of -1 month", strtotime($currentDate)));
} else {
$beforeDate = date('Y-m-d', strtotime("$currentDate -1 month"));
}
return $beforeDate;
}

php获取指定日期,前一天、前一周、前一个月、前一年,后一天,后一周,前一个月,前一年的更多相关文章

  1. JS 获取指定日期的前几天,后几天

    function getNextDate(date,day) { var dd = new Date(date); dd.setDate(dd.getDate() + day); var y = dd ...

  2. python获取指定日期的前N天日期和后N天日期

    #encoding:utf-8from datetime import date, datetime, timedelta day = date.today()now = datetime.now() ...

  3. php获取指定日期的前一天,前一月,前一年日期

    ## php获取指定日期的前一天,前一月,前一年日期   前一天的日期为: date("Y-m-d",strtotime("-1 days",strtotime ...

  4. C#获取指定日期为一年中的第几周

    /// <summary> /// 获取指定日期,在为一年中为第几周 /// </summary> /// <param name="dt">指 ...

  5. js处理日期的一些整理(js获取给定日期前一天的日期)

    var date = new Date(); alert(date);//获取当前时间 alert(date.getFullYear());//获取当前年分 alert(date.getMonth() ...

  6. ThinkPHP中如何获取指定日期后工作日的具体日期

    思路: 1.获取到查询年份内所有工作日数据数组2.获取到查询开始日期在工作日的索引3.计算需查询日期索引4.获得查询日期 /*创建日期类型记录表格*/ CREATE TABLE `tb_workday ...

  7. ThinkPHP 获取指定日期后第N个工作日具体日期

    思路: 1.获取到查询年份内所有工作日数据数组2.获取到查询开始日期在工作日的索引3.计算需查询日期索引4.获得查询日期 /*创建日期类型记录表格*/ CREATE TABLE `tb_workday ...

  8. php获取指定日期所在星期的开始时间与结束时间

    function getWeekRange($date){    $ret=array();    $timestamp=strtotime($date);    $w=strftime('%u',$ ...

  9. MSSQL 获取指定日期所在星期的第一天和最后一天日期 获取指定日期坐在月的第一天和最后一天

    ufn_GetWeekFirstAndEndDay    获取指定日期所在星期的第一天和最后一天日期 ALTER FUNCTION [dbo].[ufn_GetWeekFirstAndEndDay]( ...

  10. PHP:获取指定日期所在月的开始日期与结束日期

    /** * 获取指定日期所在月的开始日期与结束日期 * @param string $date * @param boolean 为true返回开始日期,否则返回结束日期 * @return arra ...

随机推荐

  1. php7 curl返回false error返回空串

    php7 CURLOPT_SSL_VERIFYPEER 禁用后cURL将终止从服务端进行验证.使用CURLOPT_CAINFO选项设置证书使用CURLOPT_CAPATH选项设置证书目录 如果CURL ...

  2. lucene复合条件查询案例——查询name域 或 description域 包含lucene关键字的两种方式

    方式一:使用语法表达式查询 //查询name域 或 description域包含lucene关键字 QueryParser queryParser = new QueryParser("na ...

  3. qsub

    1.qsub.sh for i in `ls`;do if [ -d $i ];then cd $i if [ -f *.sh ];then qsub -cwd -pe smp -q asm.q,al ...

  4. CDH 安装 kafka

    前言 其实cloudera已经做了这个事了,只是把kafka的包和cdh的parcel包分离了,只要我们把分离开的kafka的服务描述jar包和服务parcel包下载了,就可以实现完美集成了. 具体实 ...

  5. 【题解二连发】Construct Binary Tree from Inorder and Postorder Traversal & Construct Binary Tree from Preorder and Inorder Traversal

    LeetCode 原题链接 Construct Binary Tree from Inorder and Postorder Traversal - LeetCode Construct Binary ...

  6. pyautogui 文档(五):截图及定位功能

    截图函数 PyAutoGUI可以截取屏幕截图,将其保存到文件中,并在屏幕中查找图像.如果您有一个小图像,例如需要单击并希望在屏幕上找到它的按钮,这将非常有用.这些功能由PyScreeze模块提供,该模 ...

  7. Python 的xlutils模块

    python模块: xlrd:读取excel xlwt:写入excel 缺点:excel格式无法复用 推荐xlutils模块 可复制原excel格式 from xlutils.copy import ...

  8. git pre-push hook

    This article introduces git pre-push hook. Problem In Lean project, we use a modified version of Goo ...

  9. 关于STM32CubeMX使用LL库设置PWM输出

    HAL和LL库 HAL是ST为了实现代码在ST家族的MCU上的移植性,推出的一个库,称为硬件抽象层,很明显,这样做将会牺牲存储资源,所以项目最后的代码比较冗余,且运行效率大大降低,运行速度受制于fla ...

  10. 记录下本地修改php版本的过程, 本地PHP目录位置,PHP-FPM目录位置

    由于我在Cellar下安装了多个PHP版本,所以这里记录下如何修改本地的PHP版本 cd /usr/local/bin cp php71 php cp php71-fpm php-fpm vscode ...