codescracker


sql

SQL Dates



« Previous Tutorial Next Tutorial »


SQL Date Functions

Make sure that the format of the date you are trying to insert, matches the format of the date column in the database.

If your data contains only the date portion, then your queries will work as expected. However, if a time portion is involved, then it gets complicated.

Let's look at the most important built-in date functions for working with dates:

MySQL Date Functions

Let's look at the following table which lists the most important built-in date functions in MySQL Database :

Function Description
NOW() Returns the current date and time
CURDATE() Returns the current date
CURTIME() Returns the current time
DATE() Extracts the date part of a date or date/time expression
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
DATE_FORMAT() Displays the date/time data in different formats
DATEDIFF() Returns the number of days between two dates

SQL Server Date Functions

Let's look at the following table which lists the most important built-in date functions in SQL Server Database :

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

SQL Date Data Types

SQL Server comes with the following data types for storing the date or date/time value in the database:

MySQL comes with the following data types for storing the date or date/time value in the database:


« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test