How do I avoid storing the time portion of a datetime
in SQL Server, i.e. if I have a value of 2011-01-01 00:00:00.000
I want to store only 2011-01-01
?
I want to ensure that only the date portion is stored.
Use CASTSELECT CAST(getdate() AS date);
If you want to get a day from a date in a table, use the SQL Server DAY() function. This function takes only one argument – the date. This can be a date or date and time data type.
SQL Server Date Formats.
The DateTime data type ALWAYS stores the date AND time. So you are left with using CONVERT/CAST to obtain a particular format, or use the YEAR(), MONTH() or DAY() methods to isolate date details depending on your need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With