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 ...
随机推荐
- Cracking The Coding Interview 1.6
//原文: // // Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, w ...
- netcore 2.0 部署 到iis
.net Core2.0应用程序发布window服务器报错容易错过的配置. 1.应用程序发布. 2.IIS上新建网站. 3.应用程序池选择无托管代码. 4.服务器上安装DotNetCore.1.0.2 ...
- debug fortran
exmple: gfortran -g -fcheck=all -Wall segf.f90
- Github拉取远端的时候提示“ssh: connect to host github.com port 22: Connection timed out”错误
在使用Github的时候,如果使用到拉取远端分支的时候或者测试ssh -T git@github.com的时候可能会出现连接失败的问题,错误描述为“ssh: connect to host githu ...
- angular2.0 官网架构文档
Angular 是一个用 HTML 和 JavaScript 或者一个可以编译成 JavaScript 的语言(例如 Dart 或者 TypeScript ),来构建客户端应用的框架. 该框架包括一系 ...
- AssetBundle自动标签、打包
using System;using System.Collections.Generic;using System.IO;using UnityEditor;using UnityEngine; / ...
- 2019.2.13 SW
- 关于urls 的基础
1 普通正则 2 分组正则 url(r'/blog/(\d+)/(\d+)',views.blog) blog(request,arq1,arq2) 按照位置传参 3 分组命名 url(r'/ ...
- OSPF路由协议(二)
实验要求:使用OSPF路由协议,使每个路由器都能收集到所有网段 拓扑如下: 配置如下: R1enableconfigure terminalinterface l0ip address 192.168 ...
- linux 编译链接问题
-rpath和-rpath-link 假设有3个文件,在同一目录下,有这样的依赖关系 test->liba.so->libd.so 如果编译test的时候这样写 gcc test.c –l ...