Date and time functions for T-SQL
This topic provides reference information about date and time functions in Microsoft SQL Server and Amazon Aurora MySQL, which is valuable for database administrators and developers migrating from SQL Server to Aurora MySQL. You can understand the similarities and differences in how these two database systems handle temporal operations, including system date and time values, time zone considerations, and specific function equivalents.
Feature compatibility | AWS SCT / AWS DMS automation level | AWS SCT action code index | Key differences |
---|---|---|---|
|
|
Time zone handling. Syntax differences. |
SQL Server Usage
Date and time functions are scalar functions that perform operations on temporal or numeric input and return temporal or numeric values.
System date and time values are derived from the operating system of the server where SQL Server is running.
Note
This section doesn’t address time zone considerations and time zone aware functions. For more information, see Data Types.
Syntax and Examples
The following table lists the most commonly used date and time functions.
Function | Purpose | Example | Result | Comments |
---|---|---|---|---|
|
Return a datetime value that contains the current local or UTC date and time. |
|
2018-04-05 15:53:01.380 |
|
|
Return an integer value representing the specified date part of a specified date. |
|
4, 2018 |
|
|
Returns an integer value of date part boundaries that are crossed between two dates. |
|
25 |
How many days are left until the end of the month. |
|
Returns a datetime value that is calculated with an offset interval to the specified date part of a date. |
|
2018-04-30 15:55:52.147 |
|
|
Converts datetime values to and from string literals and to and from other datetime formats. |
|
2018-04-05 20180405 |
Default date format. Style 112 (ISO) with no separators. |
For more information, see Date and Time functions
MySQL Usage
Amazon Aurora MySQL-Compatible Edition (Aurora MySQL) provides a very rich set of scalar date and time functions; more than SQL Server.
Note
While some of the functions such as DATEDIFF seem to be similar to those in SQL Server, the functionality can be significantly different. Take extra care when migrating temporal logic to Aurora MySQL paradigms.
Syntax and Examples
Function | Purpose | Example | Result | Comments |
---|---|---|---|---|
|
Returns a datetime value that contains the current local date and time. |
|
2018-04-06 18:57:54 |
|
|
Returns a datetime value that contains the current UTC date and time. |
|
2018-04-07 04:57:54 |
|
|
Returns an integer value representing the specified date part of a specified date function. |
|
4, 2018 |
|
|
Returns an integer value of the difference in days between two dates. |
|
-25 |
|
|
Returns an integer value of the difference in date part between two dates. |
|
24 |
|
|
Returns a datetime value that is calculated with an offset interval to the specified date part of a date. |
|
2018-04-07 19:35:32 |
|
|
Converts datetime values to and from string literals and to and from other datetime formats. |
|
2018-04-05 20180405 |
Default date format. Style 112 (ISO) with no separators. |
Migration Considerations
The date and time handling paradigm in Aurora MySQL differs from SQL Server.
Be aware of the differences in data types, time zone awareness, and locale handling. For more information, see Data Types.
Summary
The following table identifies similarities, differences, and key migration considerations.
SQL Server function | Aurora MySQL function | Comments |
---|---|---|
|
|
|
|
|
|
|
|
Compatible syntax. |
|
|
Aurora MySQL supports |
|
|
|
|
|
|
|
|
Although Aurora MySQL supports both |
For more information, see Date and Time Functions