在做查询过程中,例如要实现查上个月从第一天到最后一天的佣金(提成),那我们在程序实现过程中就要让程序在上个月的范围内查询,第一天是比较好办,但最后一天就不定,要去写段函数进行月份及年份判断来得出上个月共有多少天.那就比麻烦,还有获取当前月份,当前年
在做查询过程中,例如要实现查上个月从第一天到最后一天的佣金(提成),那我们在程序实现过程中就要让程序在上个月的范围内查询,第一天是比较好办,但最后一天就不定,要去写段函数进行月份及年份判断来得出上个月共有多少天.那就比麻烦,还有获取当前月份,当前年份等常规日期获取函数
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

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

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.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment