Creating and Extracting Date/Time Data

If you are dealing with date and time data types, you will need to populate them and retrieve information from them. There are functions to do that. CURRENT_TIMESTAMP() will give you a DATETIME value. It is a standard function. Microsoft also has a getdate() function that returns the same value, but is Microsoft specific. The SYSDATETIME() function returns a DATETIME2 value.
You can also construct a specific date/time using the DATEFROMPARTS() function. You pass it year, month, and day. It will construct a date object with that value. There is also a DATETIME2FROMPARTS() function the results in a DATETIME2 value.
If you already have a date/time value, you can get information out of it with functions like YEAR(), MONTH(), and DAY(). Or you can use the generic DATEPART() function, passing a parameter specifying which part (such as HOUR) you want to extract. If you want the whole date and time to be displayed a certain way, you can use FORMAT() with a specific string that specifies how it should look.