amr_swg
asked on
First day in the week!!
Dears
In Oracle database
Any one knows a way to get the first day in the week regarding the regional settings or the database NLS format.
Thanks
In Oracle database
Any one knows a way to get the first day in the week regarding the regional settings or the database NLS format.
Thanks
This will show you the various NLS settings ...
SELECT * FROM NLS_DATABASE_PARAMETERS;
And this will (really messy, I know) tell you the first day of the week ...
select to_char(sysdate-(to_char(s ysdate,'D' )-1),'Day' ) from dual
SELECT * FROM NLS_DATABASE_PARAMETERS;
And this will (really messy, I know) tell you the first day of the week ...
select to_char(sysdate-(to_char(s
amr_swg,
You can truncate to a week - but that is the number of 7 day periods since Dec 31 of the prior year. If you know WHICH day it is, then you can use:
select next_day(sysdate,'MONDAY') from dual;
Since there's no function for "workday" in Oracle, you'd have to have your own national table of days to start with. I'd suggest perhaps using an NLS variable (like charset) to control the table you build. Or, if it is database-specific (and not session-specific), then create a function that is installed with the rest of your system:
create or replace function first_workday return varchar2 is /* The workday would be NLS-specific */
begin
return 'Monday';
end;
and you would:
select next_day(my_date,first_wor kday()) from my_table where id=124;
Good luck!
DrSQL
You can truncate to a week - but that is the number of 7 day periods since Dec 31 of the prior year. If you know WHICH day it is, then you can use:
select next_day(sysdate,'MONDAY')
Since there's no function for "workday" in Oracle, you'd have to have your own national table of days to start with. I'd suggest perhaps using an NLS variable (like charset) to control the table you build. Or, if it is database-specific (and not session-specific), then create a function that is installed with the rest of your system:
create or replace function first_workday return varchar2 is /* The workday would be NLS-specific */
begin
return 'Monday';
end;
and you would:
select next_day(my_date,first_wor
Good luck!
DrSQL
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think it's as simple as:
select trunc(sysdate,'d')
from dual;
select trunc(sysdate,'d')
from dual;
hmmm....maybe that was DrSQL's point. if so, this was just a simplification of his post of slightvw's doc.
Doc,
You can get partial credit since you took the time to paste the excerpt(I keep forgetting the Word to EE trick). ;)
You can get partial credit since you took the time to paste the excerpt(I keep forgetting the Word to EE trick). ;)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Perhaps we're not understanding your question. Are you trying to find out what the current settings deem to be the first day of the week? If so,
select to_char(next_day(sysdate,' MONDAY'),' D') from dual;
If this evaluates to 1, then your settings are for those territories that consider Monday the first day of the week (e.g. france, germany, etc.). If 2, then Sunday is deemed to be the first day of the week (as in America, Canada, etc.).
select to_char(next_day(sysdate,'
If this evaluates to 1, then your settings are for those territories that consider Monday the first day of the week (e.g. france, germany, etc.). If 2, then Sunday is deemed to be the first day of the week (as in America, Canada, etc.).
You don't like my dow function do you !
anand_2000v,
I'm not going to claim that I UNDERSTAND earthman2's function - but I'm clear on his undertstanding of Oracle's dates. As I said earlier, I was just helping out but pasting in something that slightwv referenced. I'd say split between slightwv and earthman2.
Good luck!
DrSQL
I'm not going to claim that I UNDERSTAND earthman2's function - but I'm clear on his undertstanding of Oracle's dates. As I said earlier, I was just helping out but pasting in something that slightwv referenced. I'd say split between slightwv and earthman2.
Good luck!
DrSQL
Ahhh... humility is such a rare thing these days.
DrSQL went 1 step further than I. It's a 500 pointer: My vote: 3-way split
DrSQL went 1 step further than I. It's a 500 pointer: My vote: 3-way split
SQL> select to_char(sysdate,'d') from dual;
TO_CHAR(SYSDATE,'D')
--------------------
4