Did you find this useful?
Socialize it today.


SQL Date Functions Overview

Thursday, December 15, 2011

tags SQL

SQL Date functions will vary from platform to platform. It is important to know what format of the date and/or time is stored in the database so that you can use the correct function to query the information. There are a variety of built-in functions we can use to query SQL.

Most Common Microsoft SQL Server Date Functions


FunctionDescription
GETDATE()Returns the current date and time
DATEPART()Returns a single part of a date/time
DATEADD()Adds or subtracts a time interval from a date
DATEDIFF()Returns the time between two dates
CONVERT()Displays date/time data in different formats


Most Common MySQL Date Functions


FunctionDescription
NOW()Returns the current date and time
CURDATE()Returns the current date
CURTIME()Returns the current time
DATE()Returns the date part of a date or date/time
EXTRACT()Returns a single part of a date/time
DATE_ADD()Adds a specified time interval to a date
DATE_SUB()Subtracts a specified time interval from a date
DATEDIFF()Returns the number of days between two dates
DATE_FORMAT()Displays date/time data in different formats

Understanding which function to use, and how to appropriately use it on which table field is somewhat challenging, but once you are very familiar with these functions, you will find them to be quite powerfull.

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.



Recommended Books & Training Resources

Head First SQL: Your Brain on SQL A Learners Guide SQL Cookbook