简体   繁体   English

在具有特定日期格式的sql中选择

[英]select in sql with specific format of date

I have a website project which selects dates from database. 我有一个网站项目,从数据库中选择日期。 the database stores the date in this format "2013-01-02 00:00:00.000". 数据库以“2013-01-02 00:00:00.000”格式存储日期。 but when I select the date, I want to use the format "11/06/2013" - "dd/mm/yyyy" 但是当我选择日期时,我想使用格式“11/06/2013”​​ - “dd / mm / yyyy”

here is my select 这是我的选择

-- I am trying to pass "dd/mm/yyyy"
select date from Currencies where date = '11/06/2013'

but this doesnt work. 但这不起作用。 if I change my where clause as below, it works... 如果我改变我的where子句如下,它的工作原理......

-- if I pass "mm/dd/yyyy" , it works
select date from Currencies where date = '06/11/2013'

but I must pass "dd/mm/yyyy", how can I do that? 但我必须通过“dd / mm / yyyy”,我怎么能这样做?

试试这个吧

SELECT date FROM Currencies  WHERE date = convert(datetime, '11/06/2013 00:00:00', 103)

You should avoid handling variable syntax inside your sql statements and use parameterized queries instead 您应该避免在sql语句中处理变量语法,而是使用参数化查询

check this out. 看看这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM