在MySQL中从日期,月份,年份字段创建日期 [英] Create date from day, month, year fields in MySQL

查看:801
本文介绍了在MySQL中从日期,月份,年份字段创建日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个显示文档并允许成员通过多个不同参数搜索这些文档的应用程序,其中一个参数是日期范围。

I am currently developing an application that displays documents and allows the members to search for these documents by a number of different parameters, one of them being date range.

我所遇到的问题是数据库模式不是由我自己开发的,数据库的创建者创建了一个包含day,month,year字段的date表。

The problem I am having is that the database schema was not developed by myself and the creator of the database has created a 'date' table with fields for 'day','month','year'.

我想知道如何从表中选择一个特定的日期,月份,年份,并在SQL中创建一个日期对象,这样我可以比较用户使用BETWEEN输入的日期。

I would like to know how I can select a specific day, month, year from the table and create a date object in SQL so that I can compare dates input by the user using BETWEEN.

以下是日期表的结构:

CREATE TABLE IF NOT EXISTS `date` (
  `deposition_id` varchar(11) NOT NULL default '',
  `day` int(2) default NULL,
  `month` int(2) default NULL,
  `year` int(4) default NULL,
  PRIMARY KEY  (`deposition_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


推荐答案

您可以使用 STR_TO_DATE()函数。

这篇关于在MySQL中从日期,月份,年份字段创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆