Time and Date Function

String Function

Overview

  •  

Time and Date Function

Time and Date functions

1. SYSDATE :- 

  • Purpose: Returns the current system date and time.
  • Syntax: SYSDATE
  • Example :-select sysdate as result from dual;

TRY YOURSELF

Time and Date functions

2. CURRENT_DATE :- 

  • Purpose: Returns the current date and time in the session’s time zone.
  • Syntax: CURRENT_DATE
  • Example :- select current_date as result from dual;

TRY YOURSELF

Time and Date functions

3. SYSTIMESTAMP :- 

  • Purpose: Returns the current system date and time, including time zone information.
  • Syntax: SYSTIMESTAMP
  • Example :- select systimestamp as result from dual;

TRY YOURSELF

Time and Date functions

4. ADD_MONTHS :- 

  • Purpose: Adds a specified number of months to a date.
  • Syntax: ADD_MONTHS(date, number_of_months)
  • Example :- select add_months(sysdate,2) as result from dual;

TRY YOURSELF

Time and Date functions

5. LAST_DAY :- 

  • Purpose:-  Returns the last day of the month for a specified date.
  • Syntax:-  LAST_DAY(date)
  • Example :- select last_day(sysdate) as result from dual;

TRY YOURSELF

Time and Date functions

6. NEXT_DAY :- 

  • Purpose:- Returns the next date after the given date that falls on a specified weekday.
  • Syntax:-  NEXT_DAY(date, ‘weekday’)
  • Example :-   select next_day(sysdate,’Monday’) as result from dual;

TRY YOURSELF

Time and Date functions

7. MONTHS_BETWEEN :- 

  • Purpose:-  Calculates the number of months between two dates.
  • Syntax:-  MONTHS_BETWEEN(date1, date2)
  • Example :-   select months_between(sysdate, to_date(’01-jan-2026′,’DD-MM-YYYY’))as result from dual;

TRY YOURSELF

Time and Date functions

8. TO_DATE :- 

  • Purpose: Converts a string into a date using a specified format.
  • Syntax: TO_DATE(string, format)
  • Example :-   select to_date(’25-DEC-2024′,’DD-MM-YYYY’) as result from dual;

TRY YOURSELF

Leave a Reply

Your email address will not be published. Required fields are marked *

sign up!

We’ll send you the hottest deals straight to your inbox so you’re always in on the best-kept software secrets.