How can I convert date to the order day of the month in ORACLE?
Ex: 31/07/2000 -> "Monday, the Thirty-First of July, 2000".
Is there any format date which can solve this problem?
Thanks so much!
Yes, there is - you need to combine some format elements (and modifiers) with a bit of boilerplate text (to add "the" and "of"). Like this:
select to_char( to_date('31/07/2000', 'dd/mm/yyyy')
, 'fmDay, "the " Ddspth "of" Month, yyyy') as spelled_out_date
from dual;
SPELLED_OUT_DATE
---------------------------------------
Monday, the Thirty-First of July, 2000
Note that, while the names of days of the week and calendar months depend on your session's then-current NLS_DATE_LANGUAGE, the Ddspth element will always be in English. So, alas, this solution DOES NOT WORK for other languages.
Related
I have to set the start date as 01-01-year which would be pulled from the expense date field. I have written the below query
select to_date(extract(year from rpt.expense_date),'yyyy') from rpt
How can I set the date to 01-01-year which would be pulled from above query.
Thanks in advance.
Use TRUNC to truncate to the start of the year:
SELECT TRUNC(expense_date, 'YY') FROM rpt
You can just truncate the date value:
trunc(rpt.expense_date, 'YYYY')
By default the trunc() function truncates to midnight on the specified day, equivalent to trunc(<date>, 'DD'), but you can use other elements.
In your code:
to_date(extract(year from rpt.expense_date),'yyyy')
you are only supplying the year element to to_date(); in that situation the other date elements default to the first day of the current month - so today that would give you June 1st in that year, not January 1st. That's hidden away a bit in the documentation:
If you specify a date value without a time component, then the default time is midnight. If you specify a date value without a date, then the default date is the first day of the current month.
Why
select trunc(to_date('23/06/2017','DD/MM/YYYY'), 'DAY') from dual;
returns
19.06.17
instead of expected
23.06.17?
We are on Oracle 11.
The DAY format returns the closest starting day of the week. Depending on your DB configuration, this might be a Sunday, Monday (in your case)...
You probably need the DD format instead.
Oracle doc
DAY truncates to closest SUNDAY [1]
you can use DD.
select trunc(to_date('23/06/2017','DD/MM/YYYY'), 'DD') from dual;
Your format is wrong, should be DD format:
select trunc(to_date('23/06/2017','DD/MM/YYYY'), 'DD') from dual;
Date Format Models for the ROUND and TRUNC Date Functions
DDD
DD
J
Day
I am new to OBIEE
I have date in ddmmyyyy format .
How can i create Year, Quarter, Month as separate fields out of that?
Example:
Order_date
21/11/2017
02/09/2016
OutPut
Year
2017
2016
Month
11
09
In OBIEE a time value (i.e. now()) evaluates to quarter of year as:
qarter_of_year(now())
to year as:
year(now())
to month as
month(now())
+1 to Christian - just use the actual OBI functions!
If it doesn't work you are probably not working with actual DATE data types but some numerical or varchar types.
I want to populate a table ---one column having the date for last Sunday of March and October for each year from 1800 to 2050 ..
Can someone help?
Thanks in advance
SELECT NEXT_DAY(LAST_DAY(SYSDATE)-7, 'SUN') FROM DUAL;
This gives the last date of the current month.
You just need to loop through the months instead of just giving SYSDATE.
I have to take user input in Hebrew (a month name) and convert it to an English month name. Is there any way to convert this (maybe using to_date and to_char) without a lookup table?
Update - following the suggestion for Norwegian I made this test, showing that the short Hebrew month names are longer than three characters! (I can only handle three character strings in this function)
with d as
(
select to_date('01' || lpad(rownum,2,'0') || '2011','DDMMYYYY') d from
(
select 1 from dual connect by level <=12
)
)
select to_char(d.d,'MON','NLS_DATE_LANGUAGE=HEBREW') heb_mon,
to_char(d.d,'MONTH','NLS_DATE_LANGUAGE=AMERICAN') us_mon
from d;
Which produced this data
ינואר JAN
פברואר FEB
מרץ MAR
אפריל APR
מאי MAY
יוני JUN
יולי JUL
אוגוסט AUG
ספטמבר SEP
אוקטובר OCT
נובמבר NOV
דצמבר DEC
Here's the first thing that came to my mind. I don't know enough hebrew to test with hebrew values, but this seems to work with norwegian:
with test_norwegian as (
select 'januar' month
from dual
)
select
to_char(
to_date('1 '||test_norwegian.month||' 2011', 'dd month yyyy', 'NLS_DATE_LANGUAGE=NORWEGIAN')
, 'month', 'NLS_DATE_LANGUAGE=NORWEGIAN') norwegian_month
,to_char(
to_date('1 '||test_norwegian.month||' 2011', 'dd month yyyy', 'NLS_DATE_LANGUAGE=NORWEGIAN')
, 'month', 'NLS_DATE_LANGUAGE=AMERICAN') american_month
from test_norwegian
Based on a quick scan of the Wikipedia Article: Hebrew calendar it seems reasonable to say that the Hebrew calendar does not operate the same way as the Gregorian calendar. Examples include:
There is no leap month in the Gregorian calendar for the year 5771.
Gregorian months are fixed length. Since they are based on lunar cycles, not all Hebrew months are fixed length.
If you want to convert between Hebrew and Gregorian month names, You will first need to convert from a Hebrew date to a Gregorian date then determine the Gregorian month.
A google search for "convert from hebrew date to gregorian date" produces what appears to be a large number of tools for converting between these calendars.
Here is an sourceforge project that may apply hebcal