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
Related
On my page I have an application item where the user has to select the date of birth from a date picker calendar. Since the user must be of age (according to Italian law) and I do not allow entry for people over 90, I have set the minimum and maximum to -100 and -18. When selecting the year, if the user selects a 19th century date from the date picker, the system mistakenly stores the corresponding 20th century year. How can I solve? I would like to avoid dividing the date into 3 distinct elements(day+month+year).
I solved the issue with explicit setting the format mask DD-MON-YYYY on the date picker application item. The YYYY format uses the selected century correctly. I guess that by default the date picker format considered is DD-MON-RRRR.
This helps
"What is the difference between 'YYYY' and 'RRRR' in Oracle SQL"
What is the difference between 'YYYY' and 'RRRR' in Oracle SQL
I have a table (my table ) with a varchar2 column (my_column) , this column inculdes data that may be dates, in almost every known date format. like
dd/mm/yyyy
mm/dd/yyyy
ddMONyyyy
ddmmyyyyy
yymmdd
mm.dd.yy
dd/mm/yyyy hh:24:ss
mm-dd-yyyy
and so many .
Also it could contains a free text data that may be numbers or text.
I need the possible fastest way to retrieve it as a date , and if it's cannot match any date format to retrieve null
Said that this is really a bad and dangerous way to store dates, you could try with something like the following:
select myColumn,
coalesce(
to_date(myColumn default null on conversion error, 'dd/mm/yyyy' ),
to_date(myColumn default null on conversion error, 'yyyy mm dd' ),
... /* all the known formats */
to_date(myColumn default null on conversion error ) /* dangerous */
)
from myTable
Here I would list all the possiblly expected formats, in the right order and trying to avoid the to_date without format mask, which can be really dangerous and give you unexpected results.
The simple answer is: You cannot convert the strings to dates.
You say that possible formats include 'dd/mm/yyyy' and 'mm/dd/yyyy'. So what date would '01/02/2000' be? February 1 or January 2? You cannot know this, so a conversion is impossible.
Having said that, you may want to write a stored procedure where you parse the text yourself and only convert unambiguous strings.
E.g.: Is there a substring containing colons? Then this may be the time part. In the rest of the string: Is there a four-digit number? Then this may be the year. And so on until you are either 100% sure what date/time this is or you cannot unambiguously determine the date (in which case you want to return null).
Example: '13/01/21' looks very much like January 13, 2021. Or do you allow the year 2013 in your table or even 2001 or even 1921 or ...? If you know there can be no year less then, say, 2019 in the table and no year greater than 2021, then the year must be 2021. 13 cannot be the month, so it must be the day, which leaves 01 for the month. If you cannot rule out all other options, then you would have to return null.
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.
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 have the Data in the date formats of
2nd November 2010
15th Mar 2013 -- and so on.
I need to pick up these data and insert into the field of type DATE.
How can I achieve that?
select to_char(sysdate,'ddth Month YYYY','NLS_DATE_language=American') from dual
output:
19th November 2014
select to_date('15th Mar 2013','dd"th" Mon YYYY','NLS_DATE_language=American') from dual
used to trans varchar to date format.
Hope helps you.
You just need to cast the string to a date with the appropriate format mask:
insert into your_table values (
to_date('2nd November 2010', 'ddth Month YYYY')
)
The documentation has a complete list of format models. Find out more.
However, you have a problem because your input has different formats. We cannot use the same mask to match NOVEMBER and MAR; the second date requires a mask of 'ddth Mar YYYY'.
So you will need to write a function which catches ORA-01861: literal does not match format string and applies a different mask; depending on the quality of your input data you may need to have several of these. This situation is common with applications which don't use strong data-typing, and so demand data cleansing when they interact with more rigourous systems.