开发者

SQL server datetime column filter on certain date or range of dates

There is an example for today here

开发者_如何学运维

Get row where datetime column = today - SQL server noob

I am primarily interested in 2008 only. For today it looked like

SELECT (list of fields)
FROM dbo.YourTable
WHERE dateValue BETWEEN 
   CAST(GETDATE() AS DATE) AND DATEADD(DAY, 1, CAST(GETDATE() AS DATE))

What literal value of date(s) or functions ( I need a format ) should I place there to make it work independent of local settings.


Your query will work as it stands because it uses date/time datatypes only. That is, because you have no varchar involved then SET DATEFORMAT or SET LANGUAGE settings do not apply.

And because it's SQL Server 2008, you can use the "date" type which has time part removed.

Or have I misunderstood?

Edit:

You can use this format yyyymmdd because it is the "safe" format for SQL Server regardless of settings.

See may answer here please: sql server datetime

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜