How to Convert ddmmyyyy to year(Date)? - obiee

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.

Related

Oracle Apex 19 - Date Picker - The application item stores the wrong 20th century, selecting a 19th date from the calendar

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

Applying case when date

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.

Convert Date strored as number(32,0) in oracle

I have an issue importing date from a Tririga database into a SQL database. Mainly I cant convert the date properly and it looks like is not the commont format I have seen around.
Eg date value incomming 775724400000
Running something like select to_date('765187200000', 'DDMMYYYYHH24MISS') my_date FROM dual;
give me an error
ORA-01847: day of month must be between 1 and last day of month
01847. 00000 - "day of month must be between 1 and last day of month"
I found the following info from this link seems to be also from tririga
link_help
And the size of the number are about 10 digits meanwhile this one is 12 and I know for fact this dates should be from the past 10 years (most of them)
I can't seem to find anything that gives me an answer how to convert this into proper dates.
Any suggestions?
The input number appears to be "epoch", a count of milliseconds elapsed since 1 January 1970 GMT (UTC).
To convert to date is not difficult:
select date '1970-01-01' + (775724400000 / 86400000) as dt from dual;
DT
--------------------
1994-Aug-01 07:00:00
Note the hard-coded literals: date '1970-01-01' (epoch is by definition measured from midnight on this date) and 86400000. By one of the definitions (in the previous version of the International System of Units and Weights), a second is 1/86400 of a median day. In Oracle, date arithmetic is based on the number 1 representing one day, so to convert your milliseconds to days you must divide your input by 86400 * 1000.
The most delicate question has to do with time zones (and possibly daylight saving time, also related to time zone). In most cases, epoch is measured from midnight on 1 January 1970 GMT, not from midnight on 1 January 1970 in local time. Do you need to adjust for that? Only you and your business users can answer that question.
(As an aside, the number you provided does NOT represent a date in the past 10 years - not even close.)

convert date to order day of the month

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.

Oracle Insert from TH Date Format

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.

Resources