Get day of the week: Mon, Tue..

Hi,
Is there any system function to get Mon, Tue from sysdate in Oracle:
Or should I go with series of Ifs after :
select to_char(sysdate,'D') from dual;
Tx
T

SQL> select to_char(sysdate,'FMDay') from dual
  2  /
TO_CHAR(S
Wednesday
SQL> SY.

Similar Messages

  • Getting Day of the Week

    I have a table with a bunch of columns with random stuff in them.
    One of the columns is a date + time column that has this kind of format:
    - 11-01-24 00:00:00.000000000
    - 11-01-27 02:00:00.000000000
    Now, as you can see, the first few numbers are the year, month, and date, the next few numbers are the hour, minutes, and second, but the last part, well, I'm honestly not too sure; I took over this database a while ago, so that format is a bit alien to me (if someone can clarify this, it'd be great; not important, though).
    Given this format, is it possible to get the day of the week?
    I know for some scripting and programming code, you can usually find this kind of information by using some sort of date function, but I can't seem to find one for Oracle SQL.
    It would be something like:
    SELECT *
    FROM <table>
    WHERE some_function(date_period) = 'SAT'
    Thanks a lot for any feedback!

    Hi,
    As Centinul said, the function you want is TO_CHAR, and here's one way to use it:
    WHERE   TO_CHAR ( date_period
              , 'DY'
              , 'NLS_DATE_LANGUAGE=ENGLISH'     -- If needed
              )   = 'SAT'This assumes that the data type of date_period is TIMESTAMP (or DATE).
    The third argument to TO_CHAR is optional. You can skip it if you're certain that Saturday in your session is called 'Saturday', and not 'Lördag' or 'Sabado', or something in any of the other languages that Oracle supports.
    You can use TO_CHAR wherever a string is allowed. For example:
    SELECT  TO_CHAR ( date_period
              , 'DY'
              , 'NLS_DATE_LANGUAGE=ENGLISH'     -- If needed
    FROM    table_x;To see the different things that you can put in the 2nd argument to TO_CHAR, look up "format models - date" in the SQL Language manual:
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/sql_elements004.htm#sthref396

  • Days of the week - Newbie question

    Please excuse my question as it is probably very elementary and basic to all of you, but I am just getting started learning how to use Numbers and have run into a question that I can't find an answer for in the books or on the tutorials.
    I want to have a column with the days of the week (Mon, Tues...) to automatically update as I proceed down the rows of data. I can not come up with the proper formula or the proper way to express a formula to make it perform that task. Any help would be appreciated.
    This isn't as important as most of your things since I'm retired and just using this for my personal enjoyment, but I'm sure learning a lot! Thanks, John.

    Type Monday in one row, Tuesday in the row below it. Select both. Drag down on the little circle in the bottom right of the selection box. It will fill in the rest of the days.
    A second way to do it would be using the DAYNAME formula. You will have to modify the formula depending on which row you start in but it is basically this:
    =DAYNAME(ROW()-1)
    Change the "-1" to whatever value that makes ROW()+value = 2 (assuming you want to start with Monday)
    EDIT: You did not specify if you only wanted monday through Friday. The methods above assume you want every day of the week.
    In the first method, if you only want Monday-Friday, type all the days of the week in consecutive rows, select all five cells, copy them to the next five rows, select all ten cells, then drag down. For the other method the formula will be something like
    =DAYNAME(MOD(ROW()-1,5)+2)
    Message was edited by: Badunit

  • 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

  • How can I get the day of the week to display in ical5?

    I can only see the date, e.g. 20, 21, 22 but not the day of the week, e.g. 20 Wednesday, 21 Thursday. How do change this view?  Thank you

    You need to create a stringwriter, wrap it in a printwriter, then print to the printwriter, then convert the stringwriter to a string.
    Here's an example:
    StringWriter sw = new java.io.StringWriter();
    PrintWriter pw = new java.io.PrintWriter(sw);
    e.printStackTrace(pw);
    String strError = sw.toString();
    I hope this works. I didn't test the above code. I don't think I'm leaving anything out, but it's been a while since I've done it. Either way, it should get you on the right track to get what you need.
    Hope that helps.
    Michael

  • How to pass from method to arguments to main and get the day of the week

    Hi
    Need some help, this code below doesnt fit the requirement.
    For this program, i need to: take in day, month,year of a date as int argument, return the day of the week for the date entered in App()
    In Main: call the App() to get the day of the week to display when user enter the date in dd/mm/yyyy
    StringTokenizer is required for this program.
    - How can the arguments pass back to main by returning of month & day of the week?
    - Program cant take in int and return as string
    - Date cant display day of the week
    Code
    import java.util.*;
    public class App2 {
        private int day;
        private int month;
        private int year;
             private int inputDay;
                private int inputMonth;
                private int inputYear;
        public static String App2(String day2, String month2, String year2) { // this is wrong should pass int in
              String date = day2 + month2 + year2;
             DateFormat df = new SimpleDateFormat("dd/MM/yyyy");  
              try
              Date today = df.parse(date);               
              System.out.println("Today = " + df.format(today));
              catch(ParseException e)
              if(month2.equals("01") || month2.equals("1")){month2 = "January";}              
              else if(month2.equals("02") || month2.equals("2")){month2 = "February";}              
              else if(month2.equals("03") || month2.equals("3")){month2 = "March";}              
              else if(month2.equals("04") || month2.equals("4")){month2 = "April";}              
              else if(month2.equals("05") || month2.equals("5")){month2 = "May";}              
              else if(month2.equals("06") || month2.equals("6")){month2 = "June";}              
              else if(month2.equals("07") || month2.equals("7")){month2 = "July";}              
              else if(month2.equals("08") || month2.equals("8")){month2 = "August";}              
              else if(month2.equals("09") || month2.equals("9")){month2 = "September";}              
              else if(month2.equals("10")){month2 = "October";}              
              else if(month2.equals("11")){month2 = "November";}              
              else if(month2.equals("12")){month2 = "December";}
              return month2;
        public static void main (String [ ] args){
             Scanner sc = new Scanner(System.in);
                System.out.print("Enter the date in dd/mm/yyyy: ");
                String date = sc.nextLine();
                StringTokenizer st = new StringTokenizer(date, "/");
                String day = st.nextToken();
                String month = st.nextToken();
                String year = st.nextToken();
                App2(day, month, year);
                String test = App2(day, month, year);
                     System.out.print(test);
    }Program output: 29 Aug 2010 is a Sunday

    Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.

  • Getting the same day of the week from a previous year in a Power Query calc column

    Hi Power Query users,
    Would like to get your suggestions on this problem. I have a customer that wants to see the previous year's sales for the same day of the week. So today is Friday July 25, 2014. Customer would like to see sales for the closest Friday on the previous year,
    which was Friday July 26, 2013. Next year on Friday July 26, 2015, customer would see the sales for Friday July 25, 2014 and so on. Customer operates 7 days a week, all days of the year including holidays.
    What is the most elegant way to do this? I am assuming the best thing to do is to add this date as a calculated column in the date table, but I am not quite sure the best way to write the formula (including handling of edge cases - leap years, providing
    null when the previous year is not part of the date table, etc).
    I am starting with the
    date dimension as presented by Matt Masson.
    Please help if you have any formula suggestions for this.
    Thanks

    Okay, I'm making a couple of assumptions, so please let me know if these assumptions are incorrect:
    1) Instead of all sales data being in a single column, current year and last year sales are provided in different columns,
    2) The previous year sales column shows the sales occurring on the same
    date as the current year sales (so in your example, 43214 is the sales figure for 6/1/2013.
    If the above assumptions are true, we need to modify how the lookup is done. Let's assume that you created a custom column named SameDayOfWeekLastYear. Create another column called Previous Year Date, using the following function (Date_PreviousYear)
    (date) =>
    let   
        PreviousYearDate = Date.AddYears(date,-1),
        PreviousYearDateAdjusted = if (Date.Day(date)=29 and Date.Month(date) = 2) then
                                       #date(9999,1,1)
                                   else PreviousYearDate
    in
        PreviousYearDateAdjusted
    Incidentally, I created this function the week before your query, for a different purpose. In that case, it was to get the previous year sales occurring on the same
    date as the current year sales. It actually gets to your starting point, but with all the sales data in a single column to start with. However, when the current year is a leap year and you apply the Date.AddYears function, February 29th is calculated
    as February 28th of the previous year. If you then do a lookup for previous year sales, you get February 28th sales looked-up twice (the real Feb 28th and the bogus one resulting from taking February 29th back one year). The PreviousYearDateAdjusted identifier
    puts a truly bogus date instead of a duplicated Feb 28th - one that will always return null when looking up the sales value.
    This new date column will then be used to lookup the row of the previous year sales column that corresponds to the dates in the SameDayOfWeekLastYear column.
    Assuming that the last step in your query is InsertedCustom1, create another custom column (Previous Year Net_Same Day?), which returns the sales on the same day as the current year (the result that you're after). The formula would be:
    LookupValue(InsertedCustom1[Previous Year Net], InsertedCustom1[Previous Year Date], [SameDayOfWeekLastYear])
    where LookupValue is the custom function mentioned previously. After creating this new custom column, you can then remove all of the columns you don't need.
    Hope that the preceding is somewhat clear.

  • Getting first day of the week

    Dear All.
    As there is one function module BWSO_DATE_GET_FIRST_WEEKDAY which returns the first day of the week but its Monday but in our case we require Saturday and in some cases Monday.
    our user in UK are running the same report in which i have to calculate the stock base on starting day Monday and other uses are in KSA where the starting day of the week is Saturday.
    Is there any standard option available do achieve this.
    Kind regards,

    Hi Zeeshan,
    There are two options
    Option 1: In Routine or CMOD or in Variable use offset +5 or -2 according to your reporting requirements.
    Option 2: Maintain the table entries 52 Posting periods in T0009 or in custom table with special FISCAL Variant. (i.e., each week = one posting period). Have a loop up in that table according to your requirement.
    Hope either one of the option would help you in meeting your requirement.
    Best Wishes,
    BVC

  • Oracle returning incorrect day of the week

    Hi there,
    I have a table named Performance, which includes a date field named PDATE, some other attributes such as title, etc, and a field named WEEKDAY, which includes the numerical value for the day of the week. Here is an example:
    PER#
    P#
    THEATRE#
    WEEKDAY
    PDATE
    PHOUR
    PMINUTE
    COMMENTS
    1
    1
    1
    1
    02-MAR-10
    19
    30
    Normal evening time
    2
    1
    1
    2
    03-MAR-10
    19
    30
    Normal evening time
    58
    6
    6
    3
    04-MAR-10
    19
    30
    Normal evening time
    5
    1
    1
    4
    05-MAR-10
    19
    30
    Normal evening time
    I went to verify the day of the week in a calendar (in fact I checked more than one) and I noticed that the Weekday value seems incorrect. For instance, the 2nd of March was a Tuesday so I would expect WEEKDAY to say 3 (considering Sunday to be the 1st day of the week, which is the universal norm), or perhaps 2 (considering Monday to be the 1st day of the week).
    First thing that came to mind is, since the WEEKDAY is a number field which has been pre-populated, the person who populated it made a mistake.
    So I went to verify this by running a query that would give me the correct day of the week by extracting it from the PDATE field:
    SELECT DISTINCT pdate, EXTRACT(year from pdate) year,
    to_char(to_date(pdate,'DD/MM/YYYY'),'DY') weekdaycalc, weekday
    FROM ops$yyang00.Performance
    ORDER BY pdate
    And to my astonishment, I got the following table as a return:
    PDATE
    YEAR
    WEEKDAYCALC
    WEEKDAY
    02-MAR-10
    2010
    SUN
    1
    03-MAR-10
    2010
    MON
    2
    04-MAR-10
    2010
    TUE
    3
    05-MAR-10
    2010
    WED
    4
    06-MAR-10
    2010
    THU
    5
    07-MAR-10
    2010
    FRI
    6
    08-MAR-10
    2010
    SAT
    7
    09-MAR-10
    2010
    SUN
    1
    10-MAR-10
    2010
    MON
    2
    As you can see, all of the above WEEKDAYCALC values are incorrect, and seem to match the incorrect values in WEEKDAY.
    I could perhaps understand some weird WEEKDAY numbering if there is some general database setting where I could specify any day of the week to be the first day. However, I can't think of any logical explanation on why Oracle would call a Tuesday Sunday.
    Could someone please advise what I mght be doing wrong? This is driving me insane!
    Thank you in advance for all the help and support.
    Regards,
    P.

    Hi,
    1bded5c7-e555-4306-ac86-45da83dff439 wrote:
    Thanks both Frank and Solomon for the help. I am quite new to Oracle and I feel you folks went the extra mile on the explanation
    Based on your explanations, I changed the formula so the date format would be processed as YY rather than YYY.
    SELECT DISTINCT pdate, EXTRACT(year from pdate) year,   
    to_char(to_date(pdate,'DD/MM/YY'),'DY') weekdaycalc, weekday   
    FROM Performance   
    ORDER BY pdate  
    And I got the correct values now:
    PDATE
    YEAR
    WEEKDAYCALC
    WEEKDAY
    02-MAR-10
    2010
    TUE
    1
    03-MAR-10
    2010
    WED
    2
    04-MAR-10
    2010
    THU
    3
    05-MAR-10
    2010
    FRI
    4
    06-MAR-10
    2010
    SAT
    5
    07-MAR-10
    2010
    SUN
    6
    08-MAR-10
    2010
    MON
    7
    The interesting bit here, is the original WEEKDAY field, which clearly has been created with the same mistake I did (this whole table wasn't created by me). I reckon I spotted a design bug.
    Regards,
    P.
    No; you're still calling TO_DATE on something that is already a DATE, and you're still using an implicit conversion (only now you're using a format such that the current NLS settings don't cause you to get punished.  If your DBA changes the NLS settings next week, then you will have similar errors again.)
    If you want to see what day of the week pdate is, then use:
    TO_CHAR (pdate, 'DY')
    or, to make it NLS-independent:
    TO_CHAR (pdate, 'DY', 'NLS_DATE_LANGUAGE=ENGLISH')
    This is simpler than what you posted, it's more efficient and easier to debug and to maintain, and it also gets the results you want in all cases.
    One more time: TO_DATE, as the name hints, converts something (a VARCHAR2, to be precise) TO a DATE.  If pdate is already a DATE, then what do you need to convert?  You're implicitly converting a DATE to a VARCHAR2, then explicitly converting that VARCHAR2 back to a DATE, and then calling TO_CHAR.  That's 3 function calls (1 of them error prone) where only 1 is needed.
    Also if you ever have to reconcile 2-digit years with 4-digit years (and, again, in this problem you don't) the correct way is to convert the 2-digit year to a 4-digit year, not vice-versa.
    Calling Tuesday the 1st day of the week could make sense in a particular application.

  • Range Partitioning a table based on day of the week

    I have a logging table which i want to partition into 7 partition, each one for the day of the week, eg MON,TUE, WED. I am aware and I can do a list partition by creating a parition key which stores 'DY' of the week and this means that I need to add another column to the existing table.
    I wanted to explore the option of creating a range parition based on the timestamp column that already exists. Can anyone let me know if this option is possible?
    Example
    create table test_partition
    ( log_id number,
    log_date TIMESTAMP(6),
    log_value varchar2(100)
    PARTITION BY RANGE (log_date)
    PARTITION p1_mon VALUES LESS THAN (), ---- Not sure what can be used here to create this parition.
    PARTITION p2_tue VALUES LESS THAN (),
    PARTITION p3_wed VALUES LESS THAN (),
    PARTITION p4_thu VALUES LESS THAN (),
    PARTITION p5_fri VALUES LESS THAN (),
    PARTITION p6_sat VALUES LESS THAN (),
    PARTITION p7_sun VALUES LESS THAN ()
    Any oracle guru with some suggestion for this would be highly appreciated..
    Cheers,
    VJ

    Something like:
    PARTITION P1_MON VALUES LESS THAN (TIMESTAMP'2009-03-10 00:00:00')
    ....Bear in mind that you will have to write a procedure to drop and create your daily partitions, and run that on a daily basis. Also you would be well advised to create a catchall partition that holds anything that won't go into your latest specified partition, eg:
    PARTITION P_MAX VALUES LESS THAN (MAXVALUE)

  • Range Partitioning for the day of the week

    I have a logging table which i want to partition into 7 partition, each one for the day of the week, eg MON,TUE, WED. I am aware and I can do a list partition by creating a parition key which stores 'DY' of the week and this means that I need to add another column to the existing table.
    I wanted to explore the option of creating a range parition based on the timestamp column that already exists. Can anyone let me know if this option is possible?
    Example
    create table test_partition
    ( log_id number,
    log_date TIMESTAMP(6),
    log_value varchar2(100)
    PARTITION BY RANGE (log_date)
    PARTITION p1_mon VALUES LESS THAN (), ---- Not sure what can be used here to create this parition.
    PARTITION p2_tue VALUES LESS THAN (),
    PARTITION p3_wed VALUES LESS THAN (),
    PARTITION p4_thu VALUES LESS THAN (),
    PARTITION p5_fri VALUES LESS THAN (),
    PARTITION p6_sat VALUES LESS THAN (),
    PARTITION p7_sun VALUES LESS THAN ()
    Any oracle guru with some suggestion for this would be highly appreciated..
    Cheers,
    VJ

    VJ,
    Here is an example of daily partitioning , let me know if this is what you want or you can modify this even to weekly, monthly, quarterly and yearly partitions.
    CREATE TABLE YY_EVENT
      PART_KEY       DATE                           NOT NULL,
      SUBPART_VALUE  NUMBER                             NULL,
      EVENT_NAME     VARCHAR2(30 BYTE)                  NULL,
      EVENT_VALUE    NUMBER                             NULL
    TABLESPACE TEST_DATA
    PARTITION BY RANGE (PART_KEY)
      PARTITION Y_EVENT_20090310 VALUES LESS THAN (TO_DATE(' 2009-03-11 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
        LOGGING
        NOCOMPRESS
        TABLESPACE TEST_DATA, 
      PARTITION Y_EVENT_20090311 VALUES LESS THAN (TO_DATE(' 2009-03-12 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
        LOGGING
        NOCOMPRESS
        TABLESPACE TEST_DATA
    )Regards

  • APO-SCM5 Configuring the Start Day of the week (e.g., Monday)

    Where can we configure the start day of the week (e.g., Monday or Sunday).  When we release DP to SNP, order category FA=FC Reqs are falling on Monday.  I am being asked where this is set at we have seen disturbing results where some location-producta have FC Reqs on Monday and some Sunday.  We are trying to determine if there is some sort of bug in SCM 5 as in APO4.0 all FC Reqs fell on a Monday at time= 00:00:00
    Message was edited by:
            Dan Spieth

    Hi,
    You can use planning calendar (T.code md25) to define the start of the day Eg:mon/tue/wed etc.
    Regards,
    SDS

  • Formula for calculating the average takings for a given day in the week?

    I would like to calculate the average takings for each day of the week for a given financial year.

    Rick,
    I've looked at your document, made some additions and returned it to you. In your document you were not only using AVERAGE, but also MIN and MAX. Unfortunately, MIN and MAX don't have "IF" versions, so they can't be used to selectively operate on data matching criteria in a range.
    What I did to accommodate the need for MIN and MAX was to add a column for each criteria, in this case the different days of the week.
    In your document you also indicated the need for a Chart to graphically summarize the performance by day of the week. I rearranged your summary stats table to facilitate creating a chart from that table. I chose the mixed category chart with Bars for Min and Max and a Line for Average.
    Following are Screen Shots for the modified Data table, the Stats table and the Chart:
    The key expressions are:
    For Monday receipts:
    =IF(WEEKDAY($B)=2, $G, "")
    For Monday Minimum:
    =MIN(INDIRECT("Ledger::"&CHAR(70+ROW())))
    You had pre-filled Column A with 3-letter abbreviations of the Days of the Week. I am not sure this is important, since you could have formatted the Date (Column B) to show the same information, but I didn't like seeing the abbreviations for days that didn't have data entered yet so I replaced the text with an expression...
    =IF(LEN(B)>0, LEFT(DAYNAME(WEEKDAY(B)), 3), "")
    I seems that you may have filled the table with several months worth of rows of Mon, Tue, etc. Now, if you wish, you can trim the blank rows to just a few and add more as you need them.
    Let me know if you have any questions about maintaining the document.
    Jerry

  • Change Starting Day of the Week to Sunday

    Hi,
    DBMS_SCHEDULER is assuming that Monday is the starting day of the week.
    Can this behavior be changed ? I need Sunday to the be starting day of the week.
    Regards,
    Salim

    So to start at 8am on sunday :
    start_date => next_day(trunc(sysdate),'Sunday') + 8/24OR
    begin 
    dbms_scheduler.create_schedule 
    (schedule_name => 'INTERVAL_DAILY_800', 
    start_date => next_day(trunc(sysdate),'Sunday') + 8/24,
    repeat_interval=> 'FREQ=DAILY; BYDAY= SUN,MON,TUE,WED,THU,FRI,SAT; BYHOUR=08;', 
    comments=>'Runtime: Every day (Sun-Sat) at 08:00 o'clock');
    end;
    /Best Regards
    mseberg

  • Setting the first day of the week

    Hi,
    Is there any other place in Mac OS X where I could set system's first day of the week, except iCal? In iCal it's set to Sunday, but in OmniFocus mini calendars show Monday as the first day of the week, although even there in OmniFocus preferences I've set it to use Sunday as the first day of the week. Developer says that OmniFocus is using system's settings, but nowhere in my system (except iCal) I can find where I could set the first day of the week. I have set English as the default language and order of list sorting in the International settings. Any ideas or suggestions?

    Unless it is set with the Country in the International preferences, I don't think their tech support knows what they are talking about. However, if that is where it would be set, you should be able to override it with the custom settings, but you can't.
    I'd ask them to tell you where that gets set, or is stored. Ask them what system call is used to get that value. My guess is they won't be able to tell you.

Maybe you are looking for

  • Unable to Edit "Get Info" Screen

    After hardware failure had to rebuild comp but the drive holding all my media is intact. After rebuild, installed latest ver of iTunes. Selected "Add folder" menu option to allow iTunes to recognize that folder and reset iTunes to use this folder for

  • How to put clips in order by number in List View? Opened Premier and they were reversed!

    I imported a lot of clips in numeric order from lowest to highest.  Today when I opened Premier the order was reversed in the list view from Highest to lowest number. I dont know why. I did not change anything. It did this to all my other bins also!!

  • MY FONT LOOKS DIFFERENT IN INDESIGN PAGES PLEASE HELP!!!!!

    Hello, I have a majo problem here. I have all my pages written in one font, Arial Narrow, however the width of the font looks different from page to page, it looks bold on page 1 and 2, and on page 3 it looks fine,  is there any invisible setting app

  • How to clear show isdn history

    Hi, show isdn history command will give active and inactive calls details. I wanted to clear this command output. Shall I know the relevant command for this. IOS is 12.2(8)T5 Regards Sivakondala Rao

  • Copy of FBL5N report

    Hi Friends, I have to add new pushbuttons in the application tool bar of standard FBL5N report output. For that i have copied FBL5N into ZFBL5N and also copied status  'ALV_ITEMS_AR' into  'ZALV_ITEMS_AR' and copied the function  'FI_ITEMS_DISPLAY' i