开发者

Using query to retrieve records which their createdate is a special date?

开发者 https://www.devze.com 2022-12-20 04:40 出处:网络
I have a table that has four columns. One of them is named \"CreateDate\" and it\'s datatype is \"DateTime\".

I have a table that has four columns. One of them is named "CreateDate" and it's datatype is "DateTime".

Now, what would be a true T-SQL which retrieves records that their CreateDate is for example

"2010-02-10" ?开发者_如何学C


If you wish to select all records with CreateDate on a specific date you could use something like

SELECT *
FROM YourTable
WHERE DATEADD(dd, DATEDIFF(dd,0,CreateDate), 0) = '2010-02-10'

or

DECLARE @Date DATETIME

SELECT @Date = '01 Feb 2010'

SELECT  *
FROM    YourTable
WHERE   CreateDate >= @Date
AND     CreateDate < @Date + 1

EDIT

If you wish to change the display format of the date, from SQL Server Date Formats

You could try

DECLARE @YourTable TABLE(
        CreateDate DATETIME
)

INSERT INTO @YourTable SELECT '01 Feb 2010'
INSERT INTO @YourTable SELECT GETDATE()


SELECT  *,
        CONVERT(VARCHAR(10), CreateDate, 120) DateValue
FROM @YourTable
0

精彩评论

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

关注公众号