Tips in T-SQL
This page is a reminder and how-to for my best tips in TSQL
Round DateTime values in one step
Whenever it's necessary to obtain a datetime value without hours, minutes and seconds informations,
it's possible to truncate the value with a simple conversion operation.
The suggested method is to convert DateTime value in varchar format with the following style: yyyyMMdd.
This is the only way in which a varchar format for a date could be handled by SQL Server without
wrong style conversion due to different formats in different cultures.
When the value is converted into yyyyMMdd it's possible to reassign it to a DateTime variable.
DECLARE @Today datetime
SELECT @Today = CONVERT(varchar,getdate(),112) |
After the conversion the variable @Today contains the current date with hours, minutes and seconds equal to zero.