0% found this document useful (0 votes)
34 views4 pages

Query Selet Eyame - Ada Mhs Csysoate,) "Thining - Dete",: 0dmolhscsysdate, 42) " Date Altx1 Yea Cometion Paom

This document discusses SQL date functions like ADD_MONTHS, MONTHS_BETWEEN, LAST_DAY, NEXT_DAY, ROUND, and TRUNC. It provides examples of how to use each function in a SQL query along with sample output. Exercises are included to have the reader try different date formats with the functions and observe the results. The conclusion states that various SQL date functions were implemented in sample queries to understand their use.

Uploaded by

Scorpio Zee
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)
34 views4 pages

Query Selet Eyame - Ada Mhs Csysoate,) "Thining - Dete",: 0dmolhscsysdate, 42) " Date Altx1 Yea Cometion Paom

This document discusses SQL date functions like ADD_MONTHS, MONTHS_BETWEEN, LAST_DAY, NEXT_DAY, ROUND, and TRUNC. It provides examples of how to use each function in a SQL query along with sample output. Exercises are included to have the reader try different date formats with the functions and observe the results. The conclusion states that various SQL date functions were implemented in sample queries to understand their use.

Uploaded by

Scorpio Zee
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/ 4

Lab Manual Database Management Systemn

Practical-5
AIM: Implement SQL queries using Date functions like addmonths,
months-between, round, nextday, truncate.

Date functions are scalar(Single Row) functions.


Constant date values can be passed o this functions. Also any column having date data
type can be passed as an argument.
Date format should be 'DD-MON-YY"

ADD MONTHS(date,n)
Returns new date after addingn months in the date specified by date.
If n is a negative then month will be subtracted.
Example: SELECT ADD_MONTHS (SYSDATE,3), ADD_MONTHS(SYSDATE<-3) FROM
dual;

OUTPUT:

ADD_MONTH ADD_MONTH
****--- --
30-OCT-17 30-APR-17

Exercise:
(1) Select all the employs along with the one year completion of their job. Joining
date and Date after completion of 1 should be included).

QUERY SELET EYAME_ADA mHSCsysOATE,) "Thining_Dete",


0DmolHSCSYSDATE,42)" DATE Altx1 yea Cometion PAom
EofloYCE
OUTPUT: (Draw Table)

CrnmE JoJrJGt DATE E AETER 1 YEAK ComPLETToN


Nel 11 SEf-27
11-Sef-21
Shiyam 14-SEf-21 17-SEP- 21
Tayal 97-SEP-21 14-SEP-21
Roham 11-SEf- 21 14-SeP- 27

14-SEP- 21 11-SEP-21

MONTHS_BETWEEN(date 1,date2)
Prepared By: D.G. Variya(Lecturer Compuet Dept, SKJP Bharuch)
Lab Manual Database Management System

Returns number of months between date1 and date2


It subtracts date2 trom date1
Result may be positive, negative or zero in integers as well as real numbers

Example: SELECT MONTIHSBETWEEN (31-MAR-17.31-/UL-17) FROM dual:

oUTPUT:

MONTHS BETWEEN(31-MAR-17 3 1-JUL-17)

Exercise
(2) Select all the employs along with their age.

QUERY SELECT OemE flook CmaxTHS.ETEEYCYSDATE, Oo6)/e)


AGE Rn EanoYHE

OUTPUT: (Draw Table)

EYtmE AeE
Ycel
ShYam
Teoal
Rohan 19
1

LAST DAY(date)
Returns last day of the month specified by date

EXAMPLE. SELECTLAST_DAY (SYSDATE) FROM dual

OUTPUT LAST DAY(


31-JUL-17

Exercise
(1) Select the first salary date of all the employs along with name and date of
joining
QUERY SEFT EmE LAST-DAy GYsDAIE), M0 men THSSOETE)
aini ng dte ERn Emtloyec
OUTPUT: (Draw Table)

EvAME LST-DAY NNG DATE


Nccl 30-SEf-2 17-SE-23
Shvam 30-SEP-21 1t-SE-L1
Tayr 30-SF 17-SEf-21
Prepared By: D.G Variya(Lecturer Compuet Dept, SKIP Bharuch)
NENTDAV(date.day)
It returns when the date of next named week day specited by day relative to
date
ENAMPLE SELICT NENT DAY (SYSsDATE SUNDAY) FROM dual

oUTPUT NENT DAY(SYSDATE sUNDAY')

31H-1
Exercise
(1) The first Sunday of August is celebrated as a Friendship day. Find what will be
the date on that day in year ot 2017

QUERY SEICT NOT DAY C'a1 Jul-11Unoy ) Hom DonL,

OUTPUT:
MEXTDAYc'3j-JUL -1 7, 'SUxpn)
O-AUGT-17
ROUND(date, format):
Returns the rounded date according to format.
If format is omitted, date is rounded to next day if the time is 12:00 PM or
later
Example: SELECT ROUND(SYSDATE) FROM dual
OUTPUT
ROUND(SYSDATE)

31-JUL-17

Exercise: Try yourself different date formats and observe the output.

QUERY SELECT RaD CSYSDA1E) Ram hual


sakT RoUNO('31-Jhu-21DD-moty-yy' FRom_chual;
SELECT Rounn(Th-31-22 ho-Dp-yy') R hal
SELECT RaLNDEaJAN-21 033o:45Pm
DD-may-YY HHmmissPmRom bual

Prepared By: D.G. Variya(Lecturer Compuet Dept, SKJP Bharuch)


Lab Manual Database Management System

TRUNC(date, format)
Returns Truncated date according to format
If format is omitted, date is truncated to 12:00 AM (mid night) ie. very first moment of
the date specified.

Example:SELECTtrunc(SYSDATE) FROM dual;

Output
TRUNC(SYSDATE)

30-JUL-17

Exercise: Try yourself different date formats and observe the output.

QUERY: SELECT TRUNC(SYSDA LE)FRom_dual


SELECT TAUYCO0ATE ('31-JA-21OD mn-)
FRorm dual
SELECT RUNC To 0ATE AY-31-21 mh-00-)
FRon dual
cONSLUSION: TY Ths fradi cal ve have Imelement SeLfueries
sins Doe fundionS,

SIGN:
DATE

SKJP Bharuch)
Prepared By: D.G. Variya(Lecturer Compuet Dept,

You might also like