[go: up one dir, main page]

0% found this document useful (0 votes)
11 views3 pages

Date and Time Function

The document outlines various date and time functions in SQL, including SYSDATE, CURRENT_DATE, and SYSTIMESTAMP, which return the current date and time in different formats. It also describes functions like TO_DATE for converting strings to dates, TO_CHAR for formatting dates, and ADD_MONTHS for adding months to a date. Additional functions such as EXTRACT, LAST_DAY, and NEXT_DAY are explained for extracting date parts and finding specific dates.

Uploaded by

pslambe11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Date and Time Function

The document outlines various date and time functions in SQL, including SYSDATE, CURRENT_DATE, and SYSTIMESTAMP, which return the current date and time in different formats. It also describes functions like TO_DATE for converting strings to dates, TO_CHAR for formatting dates, and ADD_MONTHS for adding months to a date. Additional functions such as EXTRACT, LAST_DAY, and NEXT_DAY are explained for extracting date parts and finding specific dates.

Uploaded by

pslambe11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

DATE AND TIME FUNCTION

1.SYSDATE

 Returns the current date and time from the system.

Example - SELECT SYSDATE FROM dual;

SYSDATE
22-AUG-25

2.CURRENT_DATE

 Returns the current date and time in the session time zone.

Example - SELECT CURRENT_DATE FROM dual;

CURRENT_DATE
22-AUG-25

3.SYSTIMESTAMP

 Returns the current date and time including fractional seconds and time zone.

Example - SELECT SYSTIMESTAMP FROM dual;

SYSTIMESTAMP
22-AUG-25 12.45.48.289000 PM +05:30

4.TO_DATE

 Converts a string to a date.

Example - SELECT TO_DATE('2025-08-22', 'YYYY-MM-DD') FROM dual;

TO_DATE('2025-08-22','YYYY-MM-DD')
22-AUG-25

5.TO_CHAR

 Converts a date or timestamp to a string in a specified format.

Example - SELECT TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS') FROM dual;

TO_CHAR(SYSDATE,'DD-MON-YYYYHH24:MI:SS')
22-AUG-2025 12:47:22

Page No.2 MAB


6.ADD_MONTHS

 Adds a number of months to a date.

Syntax - ADD_MONTHS (date, number of months)

Example - SELECT ADD_MONTHS(SYSDATE, 3) FROM dual;

ADD_MONTHS(SYSDATE,3)
22-NOV-25

7. EXTRACT

 Extracts part of a date (year, month, day, hour, etc.)

Example - SELECT EXTRACT(YEAR FROM SYSDATE) FROM dual;

EXTRACT(YEARFROMSYSDATE)
2025

8.LAST_DAY

 Returns the last day of the month that contains the date.

Syntax – LAST_DAY(date)

Example- SELECT LAST_DAY('22/Aug/2025')FROM dual;

LAST_DAY('22/AUG/2025')
31-AUG-25

9. NEXT_DAY

Returns the date of the first day of the specified name that is later than the date
supplied.

Syntax – NEXT_DAY(date, day_name)

Example- SELECT NEXT_DAY('22/Aug/2025','TUESDAY') FROM dual;

NEXT_DAY('22/AUG/2025','TUESDAY')
26-AUG-25

Page No.2 MAB


Page No.2 MAB

You might also like