Microsoft SQL Server Dates Return just Date from a DateTime

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

There are many ways to return a Date from a DateTime object

  1. SELECT CONVERT(Date, GETDATE())
  2. SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) returns 2016-07-21 00:00:00.000
  3. SELECT CAST(GETDATE() AS DATE)
  4. SELECT CONVERT(CHAR(10),GETDATE(),111)
  5. SELECT FORMAT(GETDATE(), 'yyyy-MM-dd')

Note that options 4 and 5 returns a string, not a date.



Got any Microsoft SQL Server Question?