Get a Date out of DateTime in MS-SQL

In my travelling on the web I have come across many solutions to extracting the date part out of a date time.  But somehow they all seems to miss the most obvious one, which is available in MS-SQL 2008 and newer - to simply CAST the DateTime column as a Date column:

SELECT SysID, CAST(BegDate AS DATE) As BegDate, CAST(EndDate AS DATE) AS EndDate FROM dbo.myTable

About as simple as it get's and gives you a DATE column, ready for picking.  This is an excellent way to get dates into TurboSQL tables.  For more information about how to use TurboSQL tables in Clarion, see my previous article about it.  I use TurboSQL tables quite a bit for quick access to data and when dealing with databases that come from earlier versions of MS-SQL which didn't have the DATE data type.  

Have more questions? Submit a request


Please sign in to leave a comment.
Powered by Zendesk