This area will cover the different Date and DateTime functions associated with the databases that we work with on projects or hobbies.
Name
|
Description
|
Current Date |
This is the current database system date
Microsoft:
Function: GetDate()
Example: SELECT GetDate()
Oracle:
Data Type: sysdate
Example: SELECT sysdate FROM Dual;
|
Formats
Definition(s)
Microsoft: SELECT CONVERT(VARCHAR(30), <Date>, < Format # >)
Oracle: SELECT TO_CHAR(< Date >, '< Format >')
Example(s)
Microsoft: SELECT CONVERT(varchar(30), GetDate(), 100)
Oracle: SELECT TO_CHAR(sysdate, 'Mon DD YYYY HH:MI AM') FROM Dual;
Style |
Description
|
mon dd yyyy hh:mi AM (PM) |
Microsoft: Without Century:N/A --- With Century:0 or 100
Oracle: ' Mon DD YYYY HH:MI AM' |
mm/dd/yyyy |
Microsoft: Without Century:1 --- With Century:101
Oracle: 'Mon/DD/YYYY' |
yy.mm.dd
|
Microsoft: Without Century:N/A --- With Century 102 or 2
|
dd/mm/yyyy British/French
|
Microsoft: Without Century:N/A --- With Century 103 or 3 |
dd.mm.yy German
|
| dd-mm-yy Standard: Italian
| | dd mon yy
| | Mon dd, yy
| | hh:mi:ss
| | mon dd yyy hh:mi:ss:mmmAM/PM
| | mm-dd-yy Standard: USA
| | yy/mm/dd Standard: Japan
| | yymmdd yyyymmdd
| | dd mon yyyy hh:mi:ss:mmm(24hr)
| | hh:mi:ss:mmm (24 hr)
| | yyyy-mm-dd hh:mi:ss (24hr)
| |
| | | | | |
Oracle Format Option(s):
Style |
Format
|
Numeric Month (eg: 08) |
MM
|
Abbreviated Month Name (eg: MAR) |
|
Full Month Name (eg: March) |
MONTH |
Day of Month (eg: 10) |
DD |
Abbreviated name of day (eg: Fri) |
DY |
4 Digit Year (eg. 2011) |
YYYY |
Last 2 Digits of the Year (eg: 11) |
YY |
|
|
|
|
|
|
|
|
|
|
|
|
Add Months to a Date Return the Earliest Date Return the Latest Date Return the Last Date of A Month Months Between two dates Next Day Date rounded to the unit specified String to Date Convert Date to Date at Midnight
Name
|
Description
|
Current Date |
This is the current database system date
Microsoft:
Function: GetDate()
Example: SELECT GetDate()
Oracle:
Data Type: sysdate
Example: SELECT sysdate FROM Dual;
|
Convert String to Date:
Database
|
Description
|
Oracle
|
Function: TO_DATE( 'string', [format mask], [nls_language])
string: is the string that will be converted to a date format mask (optional): This is the format that will be used to convert the string to date. nls_language (optional): This is the nls language used to convert the string to a date.
Format Mask
|
Explanation
|
YEAR
|
Year, spelled out
|
|
|
|
SQL Server
|
| |