• <legend id='8mgZa'><style id='8mgZa'><dir id='8mgZa'><q id='8mgZa'></q></dir></style></legend>

        <bdo id='8mgZa'></bdo><ul id='8mgZa'></ul>

      <small id='8mgZa'></small><noframes id='8mgZa'>

      <tfoot id='8mgZa'></tfoot>

        <i id='8mgZa'><tr id='8mgZa'><dt id='8mgZa'><q id='8mgZa'><span id='8mgZa'><b id='8mgZa'><form id='8mgZa'><ins id='8mgZa'></ins><ul id='8mgZa'></ul><sub id='8mgZa'></sub></form><legend id='8mgZa'></legend><bdo id='8mgZa'><pre id='8mgZa'><center id='8mgZa'></center></pre></bdo></b><th id='8mgZa'></th></span></q></dt></tr></i><div id='8mgZa'><tfoot id='8mgZa'></tfoot><dl id='8mgZa'><fieldset id='8mgZa'></fieldset></dl></div>

        mysql 日期与 date_format 的比较

        mysql date comparison with date_format(mysql 日期与 date_format 的比较)
        1. <small id='J6Rck'></small><noframes id='J6Rck'>

            <tbody id='J6Rck'></tbody>

          <legend id='J6Rck'><style id='J6Rck'><dir id='J6Rck'><q id='J6Rck'></q></dir></style></legend>

                  <bdo id='J6Rck'></bdo><ul id='J6Rck'></ul>
                  <tfoot id='J6Rck'></tfoot>
                • <i id='J6Rck'><tr id='J6Rck'><dt id='J6Rck'><q id='J6Rck'><span id='J6Rck'><b id='J6Rck'><form id='J6Rck'><ins id='J6Rck'></ins><ul id='J6Rck'></ul><sub id='J6Rck'></sub></form><legend id='J6Rck'></legend><bdo id='J6Rck'><pre id='J6Rck'><center id='J6Rck'></center></pre></bdo></b><th id='J6Rck'></th></span></q></dt></tr></i><div id='J6Rck'><tfoot id='J6Rck'></tfoot><dl id='J6Rck'><fieldset id='J6Rck'></fieldset></dl></div>

                  本文介绍了mysql 日期与 date_format 的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我用谷歌搜索并尝试了几种比较日期的方法,但不幸的是没有得到预期的结果.我有如下记录的当前状态:

                  I googled and tried several ways to compare date but unfortunately didn't get the result as expected. I have current state of records like following:

                          mysql> select date_format(date(starttime),'%d-%m-%Y') from data;
                  
                                +-----------------------------------------+
                                | date_format(date(starttime),'%d-%m-%Y') |
                                +-----------------------------------------+
                                | 28-10-2012                              |
                                | 02-11-2012                              |
                                | 02-11-2012                              |
                                | 02-11-2012                              |
                                | 03-11-2012                              |
                                | 03-11-2012                              |
                                | 07-11-2012                              |
                                | 07-11-2012                              |
                  

                  我想比较日期,因此这样做:

                  I would like to compare date and therefore do like this:

                          mysql> select date_format(date(starttime),'%d-%m-%Y') from data where date_format(date(starttime),'%d-%m-%y') >= '02-11-2012';
                                 +-----------------------------------------+
                                 | date_format(date(starttime),'%d-%m-%Y') |
                                 +-----------------------------------------+
                                 | 28-10-2012                              |
                                 | 02-11-2012                              |
                                 | 02-11-2012                              |
                                 | 02-11-2012                              |
                                 | 03-11-2012                              |
                                 | 03-11-2012                              |
                                 | 07-11-2012                              |
                                 | 07-11-2012                              |
                  

                  我认为结果不应该包括28-10-2012".有什么建议吗?提前致谢.

                  I believe that the result should not include '28-10-2012'. Any suggestion? Thanks in advance.

                  推荐答案

                  您的格式从根本上来说不是一个可排序的格式 - 您正在比较 字符串 和字符串28-10-2012" 大于02-11-2012".

                  Your format is fundamentally not a sortable one to start with - you're comparing strings, and the string "28-10-2012" is greater than "02-11-2012".

                  相反,您应该将日期作为日期进行比较,然后仅将它们转换为目标格式进行输出.

                  Instead, you should be comparing dates as dates, and then only converting them into your target format for output.

                  试试这个:

                  select date_format(date(starttime),'%d-%m-%Y') from data
                  where date(starttime) >= date '2012-11-02';
                  

                  (输入必须始终采用年-月-值形式,根据 文档.)

                  (The input must always be in year-month-value form, as per the documentation.)

                  请注意,如果 starttimeDATETIME 字段,您可能需要考虑更改查询以避免重复转换.(优化器很可能足够聪明来避免它,但值得检查.)

                  Note that if starttime is a DATETIME field, you might want to consider changing the query to avoid repeated conversion. (The optimizer may well be smart enough to avoid it, but it's worth checking.)

                  select date_format(date(starttime),'%d-%m-%Y') from data
                  where starttime >= '2012-11-02 00:00:00';
                  

                  (请注意,开始时将日期格式化为 dmY 是不寻常的 - 通常最好使用 yMd,即 ISO-8601 标准等.但是,上面的代码可以满足您在问题中的要求.)

                  (Note that it's unusual to format a date as d-m-Y to start with - it would be better to use y-M-d in general, being the ISO-8601 standard etc. However, the above code does what you asked for in the question.)

                  这篇关于mysql 日期与 date_format 的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                        <tbody id='2jGMa'></tbody>

                          <bdo id='2jGMa'></bdo><ul id='2jGMa'></ul>

                          <small id='2jGMa'></small><noframes id='2jGMa'>

                          • <i id='2jGMa'><tr id='2jGMa'><dt id='2jGMa'><q id='2jGMa'><span id='2jGMa'><b id='2jGMa'><form id='2jGMa'><ins id='2jGMa'></ins><ul id='2jGMa'></ul><sub id='2jGMa'></sub></form><legend id='2jGMa'></legend><bdo id='2jGMa'><pre id='2jGMa'><center id='2jGMa'></center></pre></bdo></b><th id='2jGMa'></th></span></q></dt></tr></i><div id='2jGMa'><tfoot id='2jGMa'></tfoot><dl id='2jGMa'><fieldset id='2jGMa'></fieldset></dl></div>

                            <tfoot id='2jGMa'></tfoot>
                            <legend id='2jGMa'><style id='2jGMa'><dir id='2jGMa'><q id='2jGMa'></q></dir></style></legend>