<?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天日期的更多相关文章

  1. ASP获取上月本月下月的第一天和最后一天

    上月第一天:<%=dateadd("m",-1,year(date)&"-"&month(date)&"-1" ...

  2. mysql查询今天,昨天,近7天,近30天,本月,上一月数据的方法(摘录)

    mysql查询今天,昨天,近7天,近30天,本月,上一月数据的方法分析总结: 话说有一文章表article,存储文章的添加文章的时间是add_time字段,该字段为int(5)类型的,现需要查询今天添 ...

  3. sql server2008 如何获取上月、上周、昨天、今天、本周、本月的查询周期(通过存储过程)

    我这边有一个需求要统计订单数据,需要统计订单的上传日期,统计的模块大概是 那么上月.上周.昨天.今天.本周.本月应该是怎样呢? 1.数据分析 因为今天是动态数据,我要查月份(上月.本月),应该是一个日 ...

  4. mysql查询今天,昨天,近7天,近30天,本月,上一月数据

    近期项目中用到了查询当月数据记录的功能,最初的想法是在逻辑业务里构造好时间段进行查询,当写sql语句时感觉挺麻烦.所以就到网上搜索了一下,看看是不是能有简单的方法.果然.网络资源非常强大.以下结合我的 ...

  5. 使用java的Calendar工具类获取到本月的第一天起始时间和最后一天结束时间。

    1.使用java的Calendar工具类获取到本月的第一天起始时间和最后一天结束时间. package com.fline.aic.utils; import java.text.DateFormat ...

  6. PHP获取一年中每个星期的开始和结束日期的方法

    这篇文章主要介绍了PHP获取一年中每个星期的开始和结束日期的方法,涉及php对日期操作的技巧,具有一定参考借鉴价值,需要的朋友可以参考下 本文实例讲述了PHP获取一年中每个星期的开始和结束日期的方法. ...

  7. js获取给定月份的N个月后的日期

    1.在讲js获取给定月份的N个月后的日期之前,小颖先给大家讲下getFullYear().getYear()的区别. ①getYear() var d = new Date() console.log ...

  8. PHP获取一年有几周以及每周开始日期和结束日期

    最近接了一个项目,其中有一需求是用php获取一年有几周以及每周开始日期和接触日期.在网上找些资料没有合适的,于是自己做了一份,下面通过两种方式实现PHP获取一年有几周以及每周开始日期和结束日期 代码一 ...

  9. ASP.NET中获取当日,当周,当月,当年的日期

     ASP.NET中获取当日,当周,当月,当年的日期 在ASP.NET开发中,经常会碰到要获取当日,当周,当月,当年的日期. 以下将源码贴出来和大家分享. aspx中代码如下: <table ce ...

随机推荐

  1. SQL-13 从titles表获取按照title进行分组,每组个数大于等于2,给出title以及对应的数目t。

    题目描述 从titles表获取按照title进行分组,每组个数大于等于2,给出title以及对应的数目t.CREATE TABLE IF NOT EXISTS "titles" ( ...

  2. Linux分区和挂载的理解

    在工作中经常使用到Linux,对分区和挂载的概念一直都很模糊,对网上的信息进行了整理,方便理解. 1为什么要分区(需理解硬盘的组成) 1)数据的安全性,因为每个分区的数据是分开的.所以,当你需要将某个 ...

  3. Effective Java Chapter4 Classes and Interface

    MInimize the accessibility of classes and members 这个叫做所谓的 information hiding ,这么做在于让程序耦合度更低,增加程序的健壮性 ...

  4. <Using ZooKeeper><Deploy & Use>

    安装与部署 配置过程相当简单.集群模式部署: wget http://www-us.apache.org/dist/zookeeper/stable/zookeeper-3.4.10.tar.gz t ...

  5. pytest启动浏览器,失败用例截图

    1.conftest.py # coding:utf- from selenium import webdriver import pytest driver = None @pytest.mark. ...

  6. shell脚本实例-实现监控tcp的链接状态另一种方式批量创建用户

    Array实现TCP的链接状态 #!/usr/bin/bash declare -A status type=`ss -an | grep :80|awk '{print $2}'` for i in ...

  7. shell脚本实例-while实现批量创建用户

    #!/usr/bin/bash while read line #读取一行结果 do if [ ${#line} -eq 0 ];then #如果有空行的话就跳过这次循环 contiune fi us ...

  8. 【Python】练习题

    练习1:有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列), 输出到一个新文件C中 import os file1_path="e:\\test3\\2.t ...

  9. vmware如何安装ubuntu

    一.安装vamware 二.新建虚拟机 三.安装虚拟机的镜像文件 三.正式安装ubuntu 可能会出现的问题有: 下面为百度上的方法: 敲重点: 倘若按照网上的方法:关机重启按F2无法进入BIOS.则 ...

  10. UE4 C++ Tips

    篇写的是关于UE4的C++方面的小技巧: 1.在构造函数里 //构建组件 RootComponent = CreateDefaultSubobject<USceneComponent>(T ...