---
title: "mysql 日期比较查询函数"
author: "gaozhonghui"
date: "2010-11-16T12:30:28Z"
tags: []
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2010-11-16T12:30:28Z"
id: 812642
url: "https://toptree.iteye.com/blog/812642"
---

今天，在开发邮件系统的时候发现有很多的邮件没有发送成功，想手动把数据修改。找了mysql 的日期函数

 

    获得的pubtime为String型，在sql语句中用mysql的时间函数date\_format('time','format')转换：

   

    String sqlstr="select * from do\_document where

    pub\_time&lt;date\_format('"+pubtime+"','%Y-%m-%d %H:%i:%s') order by pub\_time desc limit 0,1";

   

     然后执行该sql语句就查到了满足条件的记录。

 

    用法：

 

　　select count(\*)  from MESSAGE where date\_format(sendTime,'%Y-%m-%d') = '2010-11-16'