oracle - How to extract week number in sql -
i have transdate column of varchar2 type has following entrees
01/02/2012 01/03/2012
etc.
i converted in date format in column using to_date function. format got.
01-jan-2012 03-apr-2012
when i'm trying extract weekno, i'm getting null values.
select to_char(to_date(transdate), 'w') weekno tablename.
null null
how weekno date in above format?
after converting varchar2
date true date
datatype, convert varchar2
desired mask:
to_char(to_date('01/02/2012','mm/dd/yyyy'),'ww')
if want week number in number
datatype, can wrap statement in to_number()
:
to_number(to_char(to_date('01/02/2012','mm/dd/yyyy'),'ww'))
however, have several week number options consider:
ww week of year (1-53) week 1 starts on first day of year , continues seventh day of year. w week of month (1-5) week 1 starts on first day of month , ends on seventh. iw week of year (1-52 or 1-53) based on iso standard.
Comments
Post a Comment