在包含date_format的sql语句中使用参数 [英] Using Parameters in an sql statement which contains date_format

查看:307
本文介绍了在包含date_format的sql语句中使用参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在查询中,例如:

Select * from table_name Where DATE_FORMAT(dateTime, '%d.%m.%Y') = '%s'

在此查询中,我想为'%s'使用参数,但是在这种情况下,%d(采用日期格式)的行为也类似于参数,并且查询使用%d而不是%s的参数.

In this query i want to use parameters for '%s', but in this case %d - which is in the date format - also behaves like a parameter and the query takes the parameter for %d instead of %s.

它不是那么重要,我只是想知道是否有解决方案.其他可以用其他方式编写查询.

it is not so important, I just wondered if there is a solution. Othervise the query can be written in another way.

推荐答案

TIMESTAMP也可以用作GET_FORMAT()的第一个参数,在这种情况下,该函数将返回与DATETIME相同的值.

TIMESTAMP can also be used as the first argument to GET_FORMAT(), in which case the function returns the same values as for DATETIME.

mysql> SELECT DATE_FORMAT('2003-10-03',GET_FORMAT(DATE,'EUR')); ->'2003年10月10日'

mysql> SELECT DATE_FORMAT('2003-10-03',GET_FORMAT(DATE,'EUR')); -> '03.10.2003'

mysql> SELECT STR_TO_DATE('10.31.2003',GET_FORMAT(DATE,'USA')); ->'2003-10-31'

mysql> SELECT STR_TO_DATE('10.31.2003',GET_FORMAT(DATE,'USA')); -> '2003-10-31'

GET_FORMAT()

GET_FORMAT()

自MySQL 4.1.1.起可用.

is available as of MySQL 4.1.1.

请参见链接.

这篇关于在包含date_format的sql语句中使用参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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