php中查询时间
在做查询过程中,例如要实现查上个月从第一天到最后一天的佣金(提成),那我们在程序实现过程中就要让程序在上个月的范围内查询,第一天是比较好办,但最后一天就不定,要去写段函数进行月份及年份判断来得出上个月共有多少天.那就比麻烦,还有获取当前月份,当前年
在做查询过程中,例如要实现查上个月从第一天到最后一天的佣金(提成),那我们在程序实现过程中就要让程序在上个月的范围内查询,第一天是比较好办,但最后一天就不定,要去写段函数进行月份及年份判断来得出上个月共有多少天.那就比麻烦,还有获取当前月份,当前年份等常规日期获取函数
1.获取本月第一天凌晨0点0分0秒和最后一天23点59分59秒
$BeginDate = date('Y-m-01 00:00:00', strtotime(date("Y-m-d 00:00:00")));
$beginTime = $BeginDate;
$endTime = date('Y-m-d 23:59:59', strtotime("$BeginDate +1 month -1 day"));
var_dump(array('beginTime'=>$beginTime,'endTime'=>$endTime));
输出:array(2) { ["beginTime"]=> string(19) "2014-07-01 00:00:00" ["endTime"]=> string(19) "2014-07-31 23:59:59" }
2.获取今天凌晨0点0分0秒和今天23点59分59秒
$beginTime=date('Y-m-d 00:00:00');
$endTime = date('Y-m-d 23:59:59');
var_dump(array('beginTime'=>$beginTime,'endTime'=>$endTime));
输出:array(2) { ["beginTime"]=> string(19) "2014-07-04 00:00:00" ["endTime"]=> string(19) "2014-07-04 23:59:59" }
2.获取上个月第一天及最后一天.
echo date('Y-m-01', strtotime('-1 month'));
echo "
";
echo date('Y-m-t', strtotime('-1 month'));
echo "
";
输出:
2014-06-01
2014-06-30
2.获取当月第一天及最后一天.
$BeginDate=date('Y-m-01', strtotime(date("Y-m-d")));
echo $BeginDate;
echo "
";
echo date('Y-m-d', strtotime("$BeginDate +1 month -1 day"));
echo "
";
输出:
2014-07-01
2014-07-31
3.获取当天年份、月份、日及天数.
echo " 本月共有:".date("t")."天";
echo " 当前年份".date('Y');
echo " 当前月份".date('m');
echo " 当前几号".date('d');
echo "
";
输出本月共有多少天,当前年份,月份,号份
本月共有:31天
当前年份2014
当前月份07
当前几号04
4.获取当前时间和当前月的最后一天
echo date('Y-m-d H:m:s', time());
echo "
";
echo date('Y-m-t', time());
输出:
2014-07-04 15:07:29
2014-07-31
4.使用函数及数组来获取当月第一天及最后一天,比较实用,出自网友.
function getthemonth($date)
{
$firstday = date('Y-m-01', strtotime($date));
$lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
return array($firstday,$lastday);
}
$today = date("Y-m-d");
$day=getthemonth($today);
echo "当月的第一天: ".$day[0]." 当月的最后一天: ".$day[1];
echo "
";

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
