最近由于项目要求做一个统计功能,统计当前日期之前的前30天的记录。功能挺简单,下面将本次实现的方法和大家分享一下,方便有需要的朋友们。
其实主要就是用到了php的strtotime这个函数,strtotime('n day'),示例如下:
$days=array(); for($i=0;$i<=7;$i++){//这里数字根据需要变动 $days[]=date("Y-m-d",strtotime('-'.$i.'day')); }//http://www.phpernote.com/php-function/970.html echo '<pre class="brush:php;toolbar:false">';print_r($days);
结果将显示如下:
Array
(
[0] => 2014-03-21
[1] => 2014-03-20
[2] => 2014-03-19
[3] => 2014-03-18
[4] => 2014-03-17
[5] => 2014-03-16
[6] => 2014-03-15
[7] => 2014-03-14
)
您可能感兴趣的文章
- PHP如何获取一段时间内的日期列表
- PHP在引号前面添加反斜杠的原因及PHP去除反斜杠的办法,三种办法关闭php魔术引号
- JavaScript获取当前日期时间同时显示星期几
- PHP获得指定日期所在星期,所在月的第一天和最后一天
- php计算两个日期相差多少天(日)的函数
- php获取指定日期所在星期的开始时间与结束时间的时间戳
- php根据日期或时间戳获取干支纪年,生肖和星座信息的方法
- php提取身份证号码中的生日日期以及验证是否为未成年人的函数

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.