PHP 获取上月,本月,近15天,近30天日期
<?php
//echo $_SERVER['PHP_SELF'];
//define('ROOT_PATH',str_replace($_SERVER['PHP_SELF'],'',str_replace('\\', '/', __FILE__))); /**
* 获取统计时间
* @param $type
* 1 上月
* 2 本月
* 3 近15天
* 4 近30天
* @return array
*/
function getDateInfo($type)
{
$data = array(
array(
'firstday' => date('Ym01', strtotime('-1 month')),
'lastday' => date('Ymt', strtotime('-1 month')),
),
array(
'nowday' => date("Ymd"),
'nowday-25' => date('Ymd', strtotime('-25 day')),
'firstday' => date('Ym01', strtotime(date("Ymd"))),
'lastday' => date('Ymd', strtotime((date('Ym01', strtotime(date("Ymd")))) . " +1 month -1 day")),
),
array(
'firstday' => date('Ymd', strtotime("-15 day")),
'lastday' => date('Ymd', strtotime('-1 day')),
),
array(
'firstday' => date('Ymd', strtotime("-30 day")),
'lastday' => date('Ymd', strtotime('-1 day')),
),
);
return is_null($type) ? $data : $data[$type-1];
}
var_dump(getDateInfo(null));//获取上个月第一天与最后一天 function dateDifference($timestamp1 , $timestamp2 , $differenceFormat = '%a' )
{
$datetime1 = date_create("@$timestamp1");
$datetime2 = date_create("@$timestamp2"); $interval = date_diff($datetime1, $datetime2); return $interval->format($differenceFormat); }
echo '本月最后一天:'.date('Ymd', strtotime((date('Ym01', strtotime(date("Ymd")))) . " +1 month -1 day")).'<br>';
echo '到月底还有几天:'.dateDifference(strtotime(date('Ymd', strtotime((date('Ym01', strtotime(date("Ymd")))) . " +1 month"))),strtotime('now')).'<br>';
echo '到月底还有几天:'.(date('d', strtotime((date('Ym01', strtotime(date("Ymd")))) . " +1 month -1 day"))-date('d')).'<br>';
echo '本月已经过了几天'.date("d").'<br>';
echo strtotime('now').'<br>';
echo time().'<br>';
var_dump(date("d"));
PHP打印本月天数:
$a_days = array();
for($i=0;$i<intval(date("d"));$i++){
$a_days[]=date('Y-m-d',strtotime("-$i day"));
}
var_dump($a_days); Array ( [0] => 2017-10-25 [1] => 2017-10-24 [2] => 2017-10-23 [3] => 2017-10-22 [4] => 2017-10-21 [5] => 2017-10-20 [6] => 2017-10-19 [7] => 2017-10-18 [8] => 2017-10-17 [9] => 2017-10-16 [10] => 2017-10-15 [11] => 2017-10-14 [12] => 2017-10-13 [13] => 2017-10-12 [14] => 2017-10-11 [15] => 2017-10-10 [16] => 2017-10-09 [17] => 2017-10-08 [18] => 2017-10-07 [19] => 2017-10-06 [20] => 2017-10-05 [21] => 2017-10-04 [22] => 2017-10-03 [23] => 2017-10-02 [24] => 2017-10-01 ) PHP 日期和时间戳互换:
echo date("Y-m-d 23:59:59").'<br>';
echo strtotime(date("Y-m-d 23:59:59")).'<br>';//日期转换为时间戳
echo date("Y-m-d H:i:s",'1509033599').'<br>';//时间戳转换为日期
PHP 获取上月,本月,近15天,近30天日期的更多相关文章
- ASP获取上月本月下月的第一天和最后一天
上月第一天:<%=dateadd("m",-1,year(date)&"-"&month(date)&"-1" ...
- mysql查询今天,昨天,近7天,近30天,本月,上一月数据的方法(摘录)
mysql查询今天,昨天,近7天,近30天,本月,上一月数据的方法分析总结: 话说有一文章表article,存储文章的添加文章的时间是add_time字段,该字段为int(5)类型的,现需要查询今天添 ...
- sql server2008 如何获取上月、上周、昨天、今天、本周、本月的查询周期(通过存储过程)
我这边有一个需求要统计订单数据,需要统计订单的上传日期,统计的模块大概是 那么上月.上周.昨天.今天.本周.本月应该是怎样呢? 1.数据分析 因为今天是动态数据,我要查月份(上月.本月),应该是一个日 ...
- mysql查询今天,昨天,近7天,近30天,本月,上一月数据
近期项目中用到了查询当月数据记录的功能,最初的想法是在逻辑业务里构造好时间段进行查询,当写sql语句时感觉挺麻烦.所以就到网上搜索了一下,看看是不是能有简单的方法.果然.网络资源非常强大.以下结合我的 ...
- 使用java的Calendar工具类获取到本月的第一天起始时间和最后一天结束时间。
1.使用java的Calendar工具类获取到本月的第一天起始时间和最后一天结束时间. package com.fline.aic.utils; import java.text.DateFormat ...
- PHP获取一年中每个星期的开始和结束日期的方法
这篇文章主要介绍了PHP获取一年中每个星期的开始和结束日期的方法,涉及php对日期操作的技巧,具有一定参考借鉴价值,需要的朋友可以参考下 本文实例讲述了PHP获取一年中每个星期的开始和结束日期的方法. ...
- js获取给定月份的N个月后的日期
1.在讲js获取给定月份的N个月后的日期之前,小颖先给大家讲下getFullYear().getYear()的区别. ①getYear() var d = new Date() console.log ...
- PHP获取一年有几周以及每周开始日期和结束日期
最近接了一个项目,其中有一需求是用php获取一年有几周以及每周开始日期和接触日期.在网上找些资料没有合适的,于是自己做了一份,下面通过两种方式实现PHP获取一年有几周以及每周开始日期和结束日期 代码一 ...
- ASP.NET中获取当日,当周,当月,当年的日期
ASP.NET中获取当日,当周,当月,当年的日期 在ASP.NET开发中,经常会碰到要获取当日,当周,当月,当年的日期. 以下将源码贴出来和大家分享. aspx中代码如下: <table ce ...
随机推荐
- windows剪贴板
0x01 Windows剪贴板 Windows剪贴板是一种比较简单同时也是开销比较小的IPC(InterProcess Communication,进程间通讯)机制.Windows系统支持剪贴板IP ...
- String转换成Boolean类型
Boolean.valueOf()方法: public static Boolean valueOf(String s) { return toBoolean(s) ? TRUE : FALSE; } ...
- Centos7 LVM扩充存储空间
一. 以root账户运行命令界面:su or su - 二. 查看分区使用情况: fdisk -l /dev/sda or fdisk -l 三. 选择要扩充的分区,以sda2为例: fdisk / ...
- POJ - 1942 D - Paths on a Grid
Imagine you are attending your math lesson at school. Once again, you are bored because your teacher ...
- [转]linux shell 多线程实现
情景 shell脚本的执行效率虽高,但当任务量巨大时仍然需要较长的时间,尤其是需要执行一大批的命令时.因为默认情况下,shell脚本中的命令是串行执行的.如果这些命令相互之间是独立的,则可以使用“并发 ...
- 内存布局:栈,堆,BSS段(静态区),代码段,数据段
简介 我们程序运行的时候都是放在内存里的.根据静态.成员函数.代码段.对象.等等.放在不同的内存分块里.大概分为5块 1 栈 2 堆 3 BSS段-全局区-(静态区) 4 代码段 5 数据段 栈 ...
- L270 运动前要热身
If I'm being really honest, the only time I actually remember to stretch before a workout is when I' ...
- Diamorphine rootkit的使用
仅作LKM rootkit研究之用,滥用后果自负. 查看支持版本是否为2.6.x/3.x/4.x: uname -r 下载代码: git clone https://github.com/m0nad/ ...
- CentOS7下-bash: nano: command not found
由于安装的是纯净版系统,运行nano命令是提示没有找到该命令,以下是解决方法,用root权限的用户运行以下命令安装nano: yum install nano 遇到询问时一路点y即可. 安装好后运行: ...
- box-sizing布局
box-sizing 语法:box-sizing: content-box | border-box | inherit; 参考: https://www.jianshu.com/p/e2eb0d8c ...