Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
datetimefuction-170413055211.pptx
1. e-Infochips Institute of Training Research and Academics Limited
Date and Time Functions
Prepared by : Pranali Patel
Akshit Patel
2. Date and Time Functions
• The DATE data type is used to store date and time
information. The DATE data type has special
properties associated with it.
• It stores information about century, year, month,
day, hour, minute and second for each date value.
• The default format of Date data type is ‘DD-MM-
YY HH:MM:SS’.
• We can also change the date format using function.
3. Examples
• CURRENT_DATE:
It returns the current system date.
e.g.,
select current_date from dual;
11-APR-17
• CURRENT_TIMESTAMP:
It returns the current system date, time.
It is same as now() function.
e.g.,
select current_timestamp from dual;
11-APR-17 03.36.54.1000 PM
4. • ADD_MONTHS(d,n):
It returns the date adding number of month specified in the
function.
e.g.,
select add_months(sysdate, 3) from dual;
11-JULY-17
• LAST_DAY(d):
It returns the last date of the month specified with the
function.
e.g.,
select last_day(sysdate) from dual;
30-APR-17
5. Date conversion
• TO_CHAR:
It converts a value of DATE datatype to CHAR value.
e.g.,
select to_char ( sysdate, ‘month dd, yyyy’) from dual;
APRIL 11, 2017
• TO_DATE:
It converts characters field to date field.
e.g.,
select to_date (’11 april,2017’, ‘dd-mm-yyyy’) from dual;
11-APR-17
6. • NEXT_DAY(d,c):
It returns the date of the first week day named by c, that is
after the date named by d.
e.g.,
select next_day ( sysdate, ‘Monday’) from dual;
17-APR-2017
• MONTHS_BETWEEN(d1,d2):
It returns the number of months between d1 and d2.
e.g.,
select months_between( ‘11-july-17’, sysdate) from dual;
3
7. • ROUND:
It returns a date rounded to specific unit of measure.
e.g.,
select round(sysdate, ’yyyy’) from dual;
1-JAN-2017
• DATEDIFF(d1,d2):
It returns the difference between two dates.
e.g.,
SELECT datediff('2017-04-15',CURRENT_DATE)
from DUAL;
4
8. • DAYOFMONTH(d):
It returns a date of month.
e.g.,
SELECT dayofmonth(sysdate);
11
• DAYOFYEAR(d):
It returns a day of the year (in range 1 to 366).
e.g.,
SELECT dayofyear(sysdate);
101
• DAYOFWEEK(d):
It returns a weekday index for specified date.
e.g.,
SELECT dayofweek(sysdate);
3
9. • FROM_DAYS(n):
It returns the date value according to given number.
e.g.,
SELECT from_days(366) from dual;
0001-01-01
• MAKEDATE(y,n):
It returns a date according to given year and day of year
value.
e.g.,
select makedate (2017, 101) from dual;
2017-04-11