douyi1939 2014-10-27 14:19
浏览 31

带有单词的MySql日期格式

I'm following documentation from here: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format

This one gave me result:

WHERE  (DATE_FORMAT( date_time, '%Y %m' ) BETWEEN '2014 03' AND '2014 06') 

but this one does not:

WHERE  (DATE_FORMAT( date_time, '%Y %M' ) BETWEEN '2014 March' AND '2014 June')

I want to use date like this: April 2014

What did I do wrong? Thanks in advance for any input.

  • 写回答

1条回答 默认 最新

  • dongyupen6269 2014-10-27 14:32
    关注

    You cannot compare strings. The comparisons you are looking at are alphabetical, so nothing matches because "March" > "June".

    The comparison of two stings. M is greater than J in the alphabet therefore 2014 March is GREATER than 2014 June.

    Don't ever try to use strings for comparison factors.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害