Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
select to_char(sysdate-7,'ww') from dual;
52
1 row returned.
YEAR = Year, spelled out
YYYY = 4-digit year
YYY = last 3 digits of the year
YY = last 2 digits of the year
Y = last digit of the year
IYY = last 3 digits of ISO year
IY = last 2 digits of ISO year
I = last digit of ISO year
IYYY = 4-digit year based on the ISO standard
Q = Quarter of year (1, 2, 3, 4; JAN-MAR = 1)
MM = Month number (01-12; JAN = 01).
MON = 3-char (upper case) abbreviated name of month
Mon = 3-char (init caps) abbreviated name of month
mon = 3-char (lower case) abbreviated name of month
MONTH = Fully spelled upper-case name of month, padded with blanks to length of 9 characters
Month = Same a above, init caps
month = Same a above, lover case
RM = Roman numeral month (I-XII; JAN = I).
WW = Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.
W = Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.
IW = Week of year (1-52 or 1-53) based on the ISO standard.
D = Day of week (1-7).
DAY = Fully spelled upper-case name of day
Day = same as above, init caps
day = same as above, lower-case
DD = Day number of month (1-31)
Ddsp = Cardinal day number spelled, init caps (22 = "Twenty-Two")
Ddspth = Ordincal Day number spelled, init caps (22 = "Twenty-Second")
DDD = Day of year (1-366).
DY = 3-char upper-case abbreviated name of day
Dy = same as above, init caps
dy = same as above, lower-case
J = Julian day; the number of days since January 1, 4712 BC.
HH = Hour of day (1-12).
HH24 = Hour of day (0-23).
MI = Minute (0-59).
SS = Second (0-59).
SSSSS = Seconds past midnight (0-86399).
FF = Fractional seconds
Note 1: You can add "sp" or "spth" to any of the above numeric masks to result in either spelled cardinal numbers or spelled ordinal numbers, respectively.
Note 2: Use "fm" to toggle extra-space suppression/insertion in the to_char masks.
Note 3: You can "ALTER SESSION SET NLS_LANGUAGE = SPANISH;" for Day and Month spellings in Spanish. You may also use many other languages, instead of Spanish: such as german, french, lithuanian, italian, ukrainian, et cetera. Example:
[code]
ALTER SESSION SET NLS_LANGUAGE = SPANISH;
Session altered.
select to_char(sysdate,'fmDay, Month dd, yyyy') from dual;
Lunes, Enero 3, 2005
1 row selected.
create or replace FUNCTION WEEK_OF_YEAR (Date_i IN DATE) return NUMBER IS
offset_factor number := to_char(trunc(Date_i,'YYYY'),'D')-1;
offset_date date;
week_num number;
begin
offset_date := Date_i+offset_factor;
week_num := to_char(offset_date,'WW');
if to_char(offset_date+1,'YYYY')<>to_char(date_i,'YYYY')
and to_char(last_day(date_i),'D')=7 then
week_num := 53;
elsif week_num > 52 then
week_num := 1;
end if;
return week_num;
end;
/
set pagesize 50
col a heading "Original Dates" format a29
col b heading "Week|Number" format a9
select to_char(dates,'Day, Month dd, yyyy')a,
'Week: '||substr(' '||week_of_year(dates),-2)b
from anju;
Week
Original Dates Number
----------------------------- ---------
Sunday , December 26, 2004 Week: 1
Friday , December 31, 2004 Week: 1
Saturday , January 01, 2005 Week: 1
Sunday , January 02, 2005 Week: 2
Saturday , December 24, 2005 Week: 52
Sunday , December 25, 2005 Week: 53
Saturday , December 31, 2005 Week: 53
Sunday , January 01, 2006 Week: 1
Sunday , January 08, 2006 Week: 2
Sunday , December 31, 2006 Week: 1
Monday , January 01, 2007 Week: 1
Thursday , January 01, 2009 Week: 1
Sunday , January 04, 2009 Week: 2
Saturday , January 10, 2009 Week: 2
Sunday , January 11, 2009 Week: 3
15 rows selected.