To get date from datetime in sql

前端 未结 5 1211
醉话见心
醉话见心 2020-12-20 07:44

I have datecreated field in a table. It contains value as \"2009-12-30 11:47:20:297\" I have a query like this:

select * 
  from table 
 where          


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-20 08:06

    You can use something like this with Sql Server

    CREATE FUNCTION [dbo].[udf_DateOnly](@DateTime DATETIME)
    RETURNS DATETIME
    AS
    BEGIN
        RETURN DATEADD(dd,0, DATEDIFF(dd,0,@DateTime))
    END
    

    This line

    DATEADD(dd,0, DATEDIFF(dd,0,@DateTime))
    

    will strip out the Date portion.

提交回复
热议问题