search
Homephp教程php手册php计算出当天时间的起始点与结束的备忘

要做一个订单查询接口,需要取出当天的订单。而数据表里面只有一个下单时间字段,保存的类型是时间戳格式的。不是2010-10-5格式的。编写的查询都是有两个时间点进行限制取数据的。由于只有一个支点,没做过类似的。编写sql查询的时候。开始遇到一点小障碍。

 

 

要做一个订单查询接口,需要取出当天的订单。而数据表里面只有一个下单时间字段,保存的类型是时间戳格式的。不是2010-10-5格式的。编写的查询都是有两个时间点进行限制取数据的。由于只有一个支点,没做过类似的。编写sql查询的时候。开始遇到一点小障碍。

听同事说,可以都转化成2010-10-5的格式,数据库保存的时间戳转化成该格式,对比年,天两部分,相等就表示同年同一天了。

 

 

上面这种方式可以达到目的,不过,工作量大一点。出发点是:去转化数据库的时间戳为date格式。经过朋友的提醒,我想到了另外一个思路:统一转化成unix时间戳进行对比。这样,编写sql查询的时候变得更方便。简单了。用之前的方式,不仅编写sql的时候需要用到数据库函数。而且,php代码还是需要做同年以及同日判断(首先要同年才行,否则,日相等不符合要求的)

 

 

 

下面是当时写的代码:

 

 

/*
 *+ -------------------------------
 * 计算当天起始点和结束点时间戳 取出当天的数据
 *+ ------------------------------
 */

$year = date("Y");
$month = date("m");
$day = date("d");
$dayBegin = mktime(0,0,0,$month,$day,$year);//当天开始时间戳
$dayEnd = mktime(23,59,59,$month,$day,$year);//当天结束时间戳

 

 

$query = "SELECT * FROM `fanli_info` WHERE insert_time$dayBegin";

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

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.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment