Last Sunday of March and October - oracle

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.

Related

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.

How to Convert ddmmyyyy to year(Date)?

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.

Oracle SQL date getting first day of last quarter and last day of last quarter

I've been asked to provide an Oracle PL/SQL solution if a file is loaded into the system
for example between the dates of 1st Jan 2017 - 31st March 2017 I should
created two dates from the last quarter a loaded from date of
1st Oct 2016 and loaded to date of 31st Dec 2016. This should be future prove meaning it should work for future years, so if a file is loaded into the system lets say 21st August 2019, it should have a from date of 1st April 2019 and a to date of 30th June 2019.
This should be a PL/SQL solution most probably a procedure returning two dates to the main program and the to and from date returned should be in the format of DD/MM/YYYY.
Thanks in advance.
What about this solution?
SELECT
TO_CHAR(ADD_MONTHS(TRUNC(SYSDATE, 'Q'), -3), 'DD/MM/YYYY') AS output_from_date,
TO_CHAR(TRUNC(SYSDATE, 'Q')-1, 'DD/MM/YYYY') AS output_to_date
FROM dual;
OUTPUT_FROM_DATE OUTPUT_TO_DATE
01/04/2017 30/06/2017

ORACLE number of current week

im trying to get the number of current week by this select
to_char(sysdate) is 04.JUN.2014
select to_char(sysdate, 'WW') from dual;
it returns 23, thats okay
but when i do with sysdate-1
select to_char(sysdate-1, 'WW') from dual;
it returns 22, despite yesterday was also 23-rd week. and to_char(sysdate-1) is 03.JUN.2014
i am querying against oracle 11g2
Please, help me understand why this works so?
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.
Jan 1,2014 starts on Wednesday and that's why weeks are starting from Wednesday to Tuesday for this year.
If you use "IW" then weeks will be counting from Monday to Sunday.

Oracle week of the year

Why 12/16/2013 and 12/17/2013 are in different week?
alter session set NLS_TERRITORY=AMERICA;
select to_char(to_date('12-16-2013', 'mm-dd-yyyy'),'ww'),to_char(to_date('12-17-2013', 'mm-dd-yyyy'),'ww') from dual
If you look at the formatting models documentation, it states:
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.
01/01/2013 started on a Tuesday last year, not the first day of week. So in your test case, 12/17/2013 was on a Tuesday also, and a new "week" as oracle calculates it. Certainly, non-obvious.

Resources