From the course: SQL Server 2008 Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Using date functions

Using date functions - SQL Server Tutorial

From the course: SQL Server 2008 Essential Training

Start my 1-month free trial

Using date functions

When you're new to SQL Server you can often find the date and time data types and functions a little bit confusing just because there appears to be so many of them. We have multiple different data types for dates. We have multiple functions, DATENAME, DATEPART, DATEDIFF, DATEADD, but really you'll probably find yourself using the same two or three over and over again and it starts off with a very common function in SQL Server. The ability to say GETDATE. Even though it doesn't take any arguments we do need to use the parentheses here, both the opening and closing ones. I execute that and we get the date and time right now. This is local on the machine, working with the machine's time zone. If you're more interested in getting the universal time code, you can say GETUTCDATE and execute that, but for most people most of the time GETDATE is just fine. Now what's often the case of course is that we don't want to have the full date and time. We're interested in one particular piece of…

Contents