【问题标题】:select in sql with specific format of date在 sql 中选择特定格式的日期
【发布时间】:2013-06-19 08:41:41
【问题描述】:

我有一个从数据库中选择日期的网站项目。数据库以这种格式“2013-01-02 00:00:00.000”存储日期。但是当我选择日期时,我想使用格式“11/06/2013”​​-“dd/mm/yyyy”

这是我的选择

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

但这不起作用。如果我将 where 子句更改如下,它会起作用...

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

但我必须通过“dd/mm/yyyy”,我该怎么做?

【问题讨论】:

    标签: c# asp.net sql-server datetime


    【解决方案1】:

    试试这个

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

    【讨论】:

      【解决方案2】:

      您应该避免在 sql 语句中处理变量语法,而是使用参数化查询

      检查this

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多