Saturday, August 4, 2012

HOW TO REMOVE TIME FROM DATETIME COLUMN (T-SQL)



/*This is the best solution in my opinion*/
SELECT
TodayDateDiff = DATEADD(D,DATEDIFF(D,0,GETDATE()),0)

/*Cast to date and back to datetime*/
SELECTTodayDate= CAST(CAST(GETDATE() AS DATE) AS DATETIME)

/*Cast to string and back to date*/
SELECTTodayCast= CAST(CAST(GETDATE() AS VARCHAR(11)) AS DATETIME)

/*Cast to string and back to date*/
SELECTTodayConvert = CONVERT(DATETIME, CAST(GETDATE() AS VARCHAR(11)),120)

















Mike C.


No comments:

Post a Comment