English 中文(简体)
我如何将日期与我sql的无日期领域进行比较
原标题:how do I compare dates with non date type fields in mysql
  • 时间:2010-11-21 17:57:26
  •  标签:
  • sql
  • mysql

我的询问如下:

select id,
       date 
  from table 
 where date <  1/31/2015  && date >  11/31/2011 
最佳回答

如果你提供显示日期,某些格式将暗中/自动地转换为比较该栏的适当数据类型。 IE:

SELECT t.id,
       t.date
  FROM TABLE t
 WHERE t.date <  2015-01-31 
   AND t.date >  2011-11-31 

将某一日期/时间改为DATETIME的最有效手段是使用:

 WHERE t.date < STR_TO_DATE( 1/31/2015 ,  %m/%d/%Y )
   AND t.date > STR_TO_DATE( 11/31/2011 ,  %m/%d/%Y )
问题回答

缩略语 领域为<代码>。 YYYY-MM-DD HH:MM:SS。 如果你不使用处理日期的内在数据类型,你会再次遇到更多的麻烦。

Firstly, && is not the "and" operator in SQL; use AND.

第二,MySQL的日期总是ISO-8601。 我建议你阅读标准或研究一些实例。

第三,你可以利用“BETWEEN”的功能,在范围上找到价值。

I recommend reading

a) MySQL文件

b) 一些实例

而且

c) 参加了为开始者举办的培训课程。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签