0% found this document useful (0 votes)
3 views1 page

SQL-D4 - Date Functions

The document provides SQL queries for various date and time functions in a database. It includes commands to retrieve the system date, extract components of dates, manipulate dates by adding months, and convert character strings to date values. Additionally, it demonstrates how to find the last day of the month and retrieve specific salary information from employee records.

Uploaded by

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

SQL-D4 - Date Functions

The document provides SQL queries for various date and time functions in a database. It includes commands to retrieve the system date, extract components of dates, manipulate dates by adding months, and convert character strings to date values. Additionally, it demonstrates how to find the last day of the month and retrieve specific salary information from employee records.

Uploaded by

niya enzie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Returns the system date

SELECT SYSDATE FROM dual

returns the date and time of the system date


SELECT SYSTIMESTAMP FROM dual

CURRENT DATE - our timezone date


SELECT CURRENT_DATE FROM dual

CURRENT TIME STAMP - our timezone time


SELECT CURRENT_TIMESTAMP FROM dual

DATABASE TIME ZONE - DB time


SELECT DBTIMEZONE FROM dual

EXTRACT - seperates individual part of date


SELECT EXTRACT(YEAR FROM SYSDATE) FROM dual
1
12

to_char
select to_char(hire_date,'Month') from [Link]
jan

ADD MONTHS - adding number of months to date


SELECT ADD_MONTHS( DATE '2016-02-29', 1 ) FROM dual

start date of every date


SELECT TRUNC(DATE '2017-07-16', 'MM') FROM dual
SELECT TRUNC(SYSDATE,'MM') FROM dual

return number of months between two months


SELECT MONTHS_BETWEEN( start_date,End_date ) FROM dual

character to date value


SELECT TO_DATE( '01 Jan 2017', 'DD MON YYYY' ) FROM dual

SELECT NEXT_DAY( DATE '2000-01-01', 'SUNDAY' ) FROM dual

LAST DAY - gets last day of month


SELECT LAST_DAY(SYSDATE) FROM dual

Ajith - substr('Ajith',1,1)

Using without rank top 2nd salary

select max(salary) from [Link]


where salary < (select max(salary) from [Link])

You might also like