SQL DATE FUNCTIONS
Date functions are used
to format dates and store into tables and display.
Below are the important Date functions in MySQL.
Below are the important Date functions in
SQL Server |
|
||||||||||||||||||||
GETDATE() |
Returns the current date and time |
|
|||||||||||||||||||
DATEPART() |
Returns a single part of a date/time |
|
|||||||||||||||||||
DATEADD() |
Adds or subtracts a specified time interval
from a date |
|
|||||||||||||||||||
DATEDIFF() |
Returns the time between two dates |
|
|||||||||||||||||||
CONVERT() |
Displays date/time data in different
formats |
|
|||||||||||||||||||
SQL
Date Data Types
MySQL comes with the
following data types for storing a date/time value in the database
- DATE - format YYYY-MM-DD
- DATETIME - format: YYYY-MM-DD
HH:MI:SS
- TIMESTAMP - format: YYYY-MM-DD
HH:MI:SS
- YEAR - format YYYY or YY
SQL Server comes
with the following data types for storing a date/time value in the database
- DATE - format YYYY-MM-DD
- DATETIME - format: YYYY-MM-DD
HH:MI:SS
- SMALLDATETIME - format:
YYYY-MM-DD HH:MI:SS
- TIMESTAMP - format: a unique
number
Example:
SELECT
Now();
SELECT
Date();
SELECT
Time();
SELECT DATEDIFF('2023-01-13','2023-01-03') AS DateDiff;
No comments:
Post a Comment