DATE FOR FIRST DAY OF THE WEEK

I am new to Oracle and am looking for a procedure that will calculate the first day of the week given today's date.
Given 1/23/2000 I need to find Sunday 1/21/2000.

Hi there,
I don't think there's a built-in Oracle procedure for what you want. However...
In SQL (at least, Oracle's SQL), you have the function TO_CHAR and TO_DATE that allow you to convert a date to a string and vice-versa. They work pretty much in a similar way, that is :
TO_<something>( <data_to_convert>, <format> )
eg.: To have the day of the week for the current date, you can do
SELECT TO_CHAR( SYSDATE, 'D' ) FROM DUAL;
Wednesday, January 24th, 2001 would then return 4.
To have the day of the year, you would do
TO_CHAR( SYSDATE, 'DDD' )
Then, to have the day of the year of the first day of the week, you then could subtract the day of the week of your date from the day of the year of your date, and then add one. To be able to do math stuff of char value, you must use TO_NUMBER.
In one ugly line, you could do this by doing the following :
select to_date( (to_char(sysdate,'YYYY') &#0124; &#0124; to_char( to_number( to_char(sysdate,'DDD')) - to_number( to_char(sysdate,'D')) + 1)),'YYYYDDD') from dual;
Eurk.
Or you could write a function that would return the date of the first day of the week of a specific date, like :
create or replace
FUNCTION FDOW (P_DATE DATE) RETURN DATE
IS
R_FDOW DATE;
BEGIN
R_FDOW := to_date( (to_char(P_DATE,'YYYY') &#0124; &#0124; to_char( to_number( to_char(P_DATE,'DDD')) - to_number( to_char(P_DATE,'D')) + 1)),'YYYYDDD');
return R_FDOW;
END;
(FDOW : First Day Of Week - not really original, I know)
Then, you can call it wherever you want:
SELECT FDOW(SYSDATE) FROM DUAL;
Have fun!
Frederic Denis

Similar Messages

  • How to get the date of first day of the week

    hi ,
    how can i get the first day of the current week ?
    i have tried the following
    note : my sysdate is 3rd april 2007
    select trunc(sysdate , 'ww') from dual -- 4/2/2007
    select trunc(sysdate , 'w') from dual -- 4/1/2007
    select trunc(sysdate - 4 , 'ww') from dual -- 3/26/2007 -- shld return 25th mar 2007
    select trunc(sysdate - 4 , 'w') from dual -- 3/29/2007 -- shld return 25th mar 2007pls advise
    tks & rgds

    Hi!
    I'm considering MONDAY as the first working day of the current week. And, the code is accordingly --
    SQL> select to_char(sysdate - to_number(decode(to_char(sysdate,'DY'),'TUE','1',
      2                               'WED','2',
      3                               'THU','3',
      4                               'FRI','4')),'dd-mon-yyyy') res
      5  from dual;
    RES
    02-apr-2007Regards.
    Satyaki De.

  • Changing the first day-of-the-week on the MyTimesheets app

    IN the SAP ECC and Portal implementations of the timesheet app, we were recently able to change the display so the first day of the week is listed as Monday, rather than Sunday. I would like to do the same thing with Fiori.
    That is, when the app starts up the first view a calendar view of the whole month. If a person wants to enter time manually, they click the button labeled "manual" and a data entry screen pops up. The first day of the week listed across the top is Sunday, which does not reflect our settings in ECC. We need the 1st day of the week to be Monday.
    Is there a configuration change we can make to force the 1st day of the week to be Monday, as it is in ECC?
    thanks for your help!
    -Rob Solomon

    Hi Rob,
    Are you using Wave2 app? You could change the setting for first day of the week in CAC1 and Fiori Timesheet app will adjust te calendar accordingly.
    Nothing needs to be done for Fiori app.
    Please update UIX01HCM to SP03 if you are using Wave2 app?
    Best Regards
    Pankaj

  • From where to get "First day of the week" data for all the locales, is it present in CLDR spec 24?

    I am trying to get "First day of the week" data from CLDR spec24 but cannot find where to look for it in the spec. I need this data to calculate numeric value of "LOCAL day of the week".
    This data to implement "c" and "cc" day formats that equals numeric local day of the week.
    e.g if "First day of the week" data for a locale is 2 (Monday) , it means numeric value for local day of the week will be 1 if it is Monday that day, 2 if it is Tuesday that day and likewise.

    Hi
    If you want to week to be started with Sunday then use the following formula:
    TimestampAdd(SQL_TSI_DAY, 1-DAYOFWEEK(Date'@{var_Date}'), Date'@{var_Date}') if it's retail week(starts from Monday) then the follow below:
    TimestampAdd(SQL_TSI_DAY, 1-DAYOFWEEK(Date'@{var_Date}'), Date'@{var_Date}')
    I'm assuming var_Date is the presentation variable for prompt...
    Edited by: Kishore Guggilla on Jan 3, 2011 4:48 PM

  • Date field input help - changing first day of the week

    Hi,
    I need to change the starting day of the week  in a date field value help. I also need to change the days name in this calender.
    Thanks in Advance,
    Dekel.

    I found how to change the first day of the week, through BAdi calendar_definition.
    Can anyone help me locate the day names? (I checked - FM day_names_get dosen't get the names of the UI search help).
    Thanks,
    Dekel.
    Edited by: dekel31 on May 29, 2011 1:17 PM

  • Is there any way to change the first day of the week back to Monday in iCal for iPhone?

    With the new upgrade, iCal in my iphone is now showing Sunday as the first day of the week.
    Is there a way to change it back to Monday as the first day of the week?

    Hi! The only way I know of is changing the screen resolution. Tom

  • Calender: first day of the week problem

    on my macbook i have monday as the first day of the week in month view. on the ipad (and iphone) sunday is shown as the first day, which is a real pain for someone who has more of a visual recollection of the week than a list of dates. can i change this behaviour anywhere?
    thanks.

    many thanks for that, problem solved.
    well sort of. now i'm in new zealand with a uk formatted ipad, which will doubtless cause a ripple of problems in other apps. we will see.
    maybe the guys at apple would like to look at allowing the user to override the global settings in each app. this is important for people who work internationally. i wonder where the feedback pages are.
    thanks.

  • Want to make Monday as the first day of the week in GregorianCalendar. how?

    hi
    I need to know what day is the first of the month is. for example the 1st of Nov 2004 is Moday and 1st of Dec 2004 is saturday.
    I am using the GregorianCalendar:
    1.  GregorianCalendar calendar = new GregorianCalendar(2004,11,1);    //set date to 1st Nov 2004
    2.  int firstDay = calendar.get(Calendar.DAY_OF_WEEK);now firstDay is 2. This is because the week starts from Sunday, so Monday is the 2nd day.
    But I am in Uk and my Uk Calendar shows monday as the first day (even in Windows 2000 Calendar).
    I would like the GregorianCalendar to have Monday as the first day of the week, so that the
    int firstDay = calendar.get(Calendar.DAY_OF_WEEK);
    returns 1 in the above case.
    I also tried adding
    calendar.setFirstDayOfWeek(Calendar.MONDAY); just between line 1 and line 2, but it did not help.
    This is because i don't want to manually subtract 1. If i manually subtract one, then the program might not work in other locale and timezones.
    Also if I subtract 1, then for 1 Feb 2004,
    int firstDay = calendar.get(Calendar.DAY_OF_WEEK);
    will return 1 as 1st Feb 2004 falls on Sunday. so if i subtract 1 it will be 0, so I have to do a extra checking for 0.
    Is there anyway to make the Calendar have Monday as the first day of the week??
    Tanveer

    hi
    I need to know what day is the first of the month is.Why does this matter? Since we know that 1 == Sunday and 2 == Monday... Why do you need Monday to be == 1? and couldn't you just subtract 1 if it's so important?
    for example the 1st of Nov 2004 is Moday and 1st of
    Dec 2004 is saturday.
    I am using the GregorianCalendar:
    1.  GregorianCalendar calendar = new
    GregorianCalendar(2004,11,1);    //set date to 1st Nov
    2004
    2.  int firstDay = calendar.get(Calendar.DAY_OF_WEEK);now firstDay is 2. This is because the week starts
    from Sunday, so Monday is the 2nd day.
    But I am in Uk and my Uk Calendar shows monday as the
    first day (even in Windows 2000 Calendar).
    I would like the GregorianCalendar to have Monday as
    the first day of the week, so that the
    int firstDay = calendar.get(Calendar.DAY_OF_WEEK);
    returns 1 in the above case.
    I also tried adding
    calendar.setFirstDayOfWeek(Calendar.MONDAY);[/cod
    ] just between line 1 and line 2, but it did not help.
    This is because i don't want to manually subtract 1.
    If i manually subtract one, then the program might not
    work in other locale and timezones.
    Also if I subtract 1, then for 1 Feb 2004,
    int firstDay = calendar.get(Calendar.DAY_OF_WEEK);
    will return 1 as 1st Feb 2004 falls on Sunday. so if i
    subtract 1 it will be 0, so I have to do a extra
    checking for 0.
    Is there anyway to make the Calendar have Monday as
    the first day of the week??
    Tanveer

  • First day of the week in calendar

    In the UK (as in many countries) the week starts on Sunday and calendars normally reflect this. With iPhone the week starts on Monday (in UK) but in Ireland it starts on Sunday. I really can't use a calendar showing Monday as the first day of the week (it's too confusing when compared to printed calendars and iCal on the computer). If I set iPhone calendar to Ireland that's fine for a while but soon it reverts to UK and Monday. Is it possible to make this calendar show the correct day all the time?

    Yes, it's possible, by changing Settings > General > International > Region Format to something other than the UK. Setting it to the United States will give you a week starting on Sunday. But, that setting also controls the way dates and phone numbers are displayed, so those are affected as well. But, maybe that's already how you already "set iPhone calendar to Ireland," in which case, I'm not sure why it's reverting back, unless it's resulting from when you sync the phone to your computer.

  • First day of the week changing wp8.1

    In WP8.1 is there a way, other than changing the country setting, of changing the first day of the week?  If that is the only way is there a list of which countries start on which particular day and have which particular number format?  

    Thank you again for you help Mathias, unfortunately that doesn't have which day of the week is first. 
    I will try answers.microsoft.com although I believe a bug tracker would allow me to flag the problem and then it would be fixed for everyone, not just me solving it through trailing every countries date format.

  • Moving a GregorianCalendar to the first day of the week

    I'm using a GregorianCalendar class in order to get the time stamp for the nearest Sunday's date.
    here's what I'm trying to do:
    1. get a timeStamp and set it into a date
    Date startDate = new Date(startTime);2. create a new GregorianCalendar using the above date as the start time.
    GregorianCalendar calendar = new GregorianCalendar((startDate.getYear()+1900),startDate.getMonth(),startDate.getDate());3. the tricky part: make sure the calnedar's date is set to Sunday, if the current date is on any day other then Sunday, I will have to move it back to the nearest Sunday. I'm trying to do this by using:
    calendar.set(Calendar.DAY_OF_WEEK, 0);     for some reason this does not work...
    am I doing anything wrong here?

    thanks for that info but the problem is still there. here's some more input:
    //creating the date, the ts here is 1153858800000 which is the dated in 7/25/2006
    Date startDate = new Date(startTime);
    //creating the new calendar
    GregorianCalendar calendar = new GregorianCalendar((startDate.getYear()+1900),startDate.getMonth(),startDate.getDate());
    //setting the calendar to the first hour (not sure it necessary)
    calendar.set(Calendar.HOUR, 1);
    //setting the calendar to the first day of the week
    calendar.set(Calendar.DAY_OF_WEEK, 1);
    //this returns 1153778400000 which is still dated 7/25/2006 whic is a Tuesday I would expect it to returns a different date
    calendar.getTimeInMillis()     

  • Figure out dates corresponding to days of the week, constructing a schedule

    Hi everyone,
    I'm sorry if this topic has already been covered. I've searched the forums for an answer, but did not see anything I took to be an answer (I'm not very good at this).
    I'm trying to make a simple table to tell me which dates a particular day of the week falls on. For instance, I'm making a syllabus for a class that meets every Tuesday and Thursday. I want to know which dates corresponds to every Tuesday and Thursday from here on out.
    I currently have a table with two columns. The first column is the day of the week. The first row is Tuesday, the second is Thursday, the third Tuesday, etc. I was able to do this easily with auto fill. I want the next column to be the date.
    Here's a picture of what I mean:
    Is there a formula that will let me do this?
    Thanks!

    Hi Macademic,
    How about putting both into the first column?
    Select all of column A and use the Cell Format inspector to set the format as Date and Time, with the Date: and Time: pop-up menus set to:
    Date: Mon, Jan 5, 2009
        or: Monday, January 5, 2009
        or  to a Custom format, Date and Time, including only the elements you want in the format you want them.
    Time: None
    Enter the starting date into A2, and confirm that it is either a Tuesday or a Thursday.
    In A3, enter
    =A2+2 (if the course starts on a Tuesday)
    or
    =A2+5 (if the course starts on a Thursday)
    In A4, enter
    =A2+7
    Select A3 and A4, then grab the control (small circle at the lower right corner of the selection) and drag down until you reach the last date of the course.
    Regards,
    Barry

  • Get date of first day of current week

    HI!
    Why does the following method do not return the date of the first day of the week in which the given date lies?
    public static int getFirstDayOfWeek(int year, int month, int date) { 
    GregorianCalendar GregCalendar = (GregorianCalendar)
    new GregorianCalendar(year, month, date).getInstance();
    while(GregCalendar.get(Calendar.DAY_OF_WEEK)!= Calendar.MONDAY) {
    GregCalendar.roll(Calendar.DATE, false);
    return GregCalendar.get(Calendar.DATE);     
    What I want the method to do:
    year = 2003
    month = Calendar.JANUARY
    date = 8
    ==> GregCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY
    ==> GregCalendar.roll(Calendar.DATE, false);
    ==> GregCalendar.get(Calendar.DATE) == 7 (?????????)
    ==> GregCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY
    ==> GregCalendar.roll(Calendar.DATE, false);
    ==> GregCalendar.get(Calendar.DATE) == 6
    ==> GregCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY
    ==> return GregCalendar.get(Calendar.DATE)
    But in reality, it always returns 6 grrrrrrrr
    What is wrong wirh it?
    Yours RB

    public Date getCurrentMonday()
            Date monday = null;
            Calendar rightNow = Calendar.getInstance();
            int day = rightNow.get(Calendar.DAY_OF_WEEK);
            int distance = 0;
            if (day == Calendar.MONDAY)
                monday = rightNow.getTime();
            else
                distance = day - Calendar.MONDAY;
                if (distance == -1)
                    distance = 6;
                monday = (Date) (rightNow.getTime());
                monday.setTime(monday.getTime() - 1000 * 60 * 60 * 24 * (distance));
            return monday;
        }

  • Changing the calendar settings: Sunday as the first day of the week

    Dear Masters of SAP universe,
    In ECC6.0, I am using a LIS info-structure with the period split set to week.
    I would like to know how can I change the calendar settings in order to consider Sunday as the first day of the week, instead of Monday.
    For example:
    A sales order created on Dec 12th creates the record 201049 in the info structure S900 - SPWOC.
    I would like to have it as 201050, where 50 is the currently week in the system.
    I already checked OSS notes and the transaction SCAL for customizing. But I did not find a solution this issue.
    Your help is highly appreciated!

    hi,
    this seems to be a calendar issue.
    please check for OSS also - 1158474.
    balajia

  • United Kingdom Regional Format sets Monday as the first day of the week.

    With the Region Settings (Settings -> General -> International -> Region Format) set to United Kingdom, Calendar displays Monday as the first day of the week. I have seen other posts whereby it was suggested to change to US Internationalization but this will also change the date and telephone number formats to US settings, far more frustrating.
    Have I been sheltered from properly formatted calendars all my life or is this a mistake and it should start the week on Sunday. It is consistent in both the Week and Month view.
    Am I crazy or does anyone else agree with is?

    Same here. One of the first things I do in this sort of application is switch week start to Mondays.
    Terry, East Grinstead, UK
    Message was edited by: Terry P

Maybe you are looking for

  • Premier Elements 7 aspect ratio problem, XP

    I bought this program from a famous online store in UK and when I installed it I was unable to change the aspect ratio for my production. I got in touch with the trader who said they could not help me with this and gave me my money back, without aski

  • Tango Video calls on Nokia Belle

    When will Nokia make Tango or any other video calls application available on Nokia Belle mobiles, such appliocation are very imoprtant to have, and Nokia should invite the developers to make such applications compatible with our Nokia latest mobiles.

  • Structure to fill MIRO details

    I am creating a new smartform to print output to miro transaction .Is there any standard structure like lbbil_invoice ( for invoice)available to pass data to smartform? or can i create a structure to get data from print program? which is advicable? o

  • BUS_TRANS_MSG:Technical error Could not determine module name

    Hi, 1) Sales documents were not replicating to R/3 system,bdocs failed with the following Techical error. Could not determine module name: BUS_TRANSACTION_MESSAGE GENKEY: REP_GET_RECIPIENT Service that caused the error: SMOH_REPLICATION_WRAPPER_MSG.

  • Where can I find email settings?

    I am trying to receive emails on my phone. It is saying it is unable to connect to server. No response for server. Does anyone know what kind of account this is and what the settings are. I am having a hard time finding it.