Months in a year, days in a week & dates in a month

Hi guys
I want 3 sql queries which can giv me the foll
all months in a year (jan, feb ,mar.....)
all days in a week (mon, tue, wed....)
all dates in a month (1,2,3,4,5,.....)
how can i do this in oracle
Thanx
Sushant

Here you go.
<code>
SELECT to_char( add_months(sysdate, r), 'MONTH') AS month
FROM ( SELECT rownum AS r
FROM all_objects
WHERE rownum <= 12)
SELECT to_char(sysdate+r, 'DAY') AS day, to_char(sysdate+r, 'D') AS day_number
FROM ( SELECT rownum-1 AS r
FROM all_objects
WHERE rownum <= 7)
SELECT sysdate+r as month_date, to_char( sysdate+r, 'DD') AS month_day
FROM ( SELECT rownum-to_number(to_char( sysdate, 'DD')) AS r
FROM all_objects
WHERE rownum <= to_number(to_char( last_day(sysdate), 'DD')))
</code>
Ras malai! APC

Similar Messages

  • 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

  • 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.

  • Months/ days of the week not in English?

    Hi,
    When connecting my iPhone with iTunes for the first time, it seems that it picked up the location from my computer’s regional and languages, and as a result the menus on my calendar and weather applications, as well as the time on the home screen (month, day) - are in different language. Everything related to days of the week and months – not in English.
    I’ve changed the main setting from the control panel, installed the iTunes again, but I can’t find how I could change it for the iPhone. (The location within the iTunes store is correct.)
    Any suggestions?

    Thanks Phil,
    I don’t know how it got messed up… Seems ok now, but this is how it looked like:
    Language – English
    Voice control – Английски
    Keyboards 1 – Bulgaria ON
    Region Format – Bulgarian

  • I am trying to find out if I can change a setting of the calendar in my iPhone.   When I view calendar, in month, I would like to view it with the starting day of the week being Monday, not Sunday.  Is it possible to make this change? SS

    I am trying to find out if I can change a setting of the calendar in my iPhone. 
    When I view calendar, in month, I would like to view it with the starting day of the week being Monday, not Sunday.  Is it possible to make this change?

    Hello SMEvans32
    You can use iCloud to share the Calendar, that way she will always be up to date on that particular section of your work calendar. If you want to use iCloud, I would recommend backing up so you have a safe copy of your data.
    iCloud: Calendar sharing overview
    http://support.apple.com/kb/PH2689
    iCloud Setup
    http://www.apple.com/icloud/setup/
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • Wrong starting day of the week printing calendar in month view

    I'm trying to print a month view calendar with the weeks starting from Monday.
    In "Preferences" -> "General tab" ->"Start week on:"  I've set Monday, and it is properly viewed in Calendar, but when I try to print it in the preview I see Tuesday as first day of the week.
    This happens on many MacBook that I've tried, all with Yosemite and Italian regional settings.
    The only way to resolve this issue is to open "System Preferences" ->"Language & Region" and change the "First day of the week:" on Sunday in all my "Preferred Languages" (both Italian and English), to have the printing preview of a calendar starting on Monday!
    Is there an other way?
    Is this a bug that should be submitted to Apple to get a "patch" on future releases of Mac OS X?
    I know, it is a tiny issue, but annoying.
    Mauro

    Re: Calendar printing problem

  • Sunday as the first day of the week in month view on the iTouch

    Does anyone know how to change Sunday to the first day of the wek in the month view of the calendar on itouch?
    BTW, I have selected Sunday as the first day of the week in ical on my imac which syncs the ipod itouch. Am I forgetting something or is there a hidden preferences page?
    Tom

    TLGreen58 wrote:
    Does anyone know how to change Sunday to the first day of the wek in the month view of the calendar on itouch?
    BTW, I have selected Sunday as the first day of the week in ical on my imac which syncs the ipod itouch. Am I forgetting something or is there a hidden preferences page?
    Tom
    Hi,
    OMG! How bizzarre, another quirk of the "Region Fortmats" setting.
    *Settings > General > International > Region Format*
    If I set mine to U.K. (where I happen to live), Monday is apparently the first day of the week on the calendar and I have no 12/24 hour clock option.
    If set to U.S., Sunday is the first day and the 12/24 hour clock option is available.
    I guess changing the Region is your answer.
    How odd! Not to say irritating.
    Dud.
    Message was edited by: Duddo

  • Icloud calendar not on correct day when in Week or Month view

    Hi icloud calendar highlights a day behind, I almost forgot to pay a bill due as calendar was showing yesterdays date highlighted when viewed in Week or Month view! and assumed the bill was due tomorrow but of course it's due today!
    It's correct when it displays the DAY, but not week or month. (In week or month view ithighlights the Tuesday) How can I get ical to show the correct date and highlight this?
    For the record I assume its becasue I live in NZ and are ahead of the US. Since all my computers and phones etc automatically change and display ot the date correctly, how come this calendar in icloud doesn't?
    I'm logging on through a mac at work which has todays (Wednesday 11th April) set fine, but when I view the ical in it's month or week view, it highlights today as being Tuesday! Is this a bug or is there a fix?
    cheers
    confused kiwi

    I fixed the issue myself, by editing my name on the icloud initial page. Changed the time setting from Pacific to New Zealand. This appears to have solved the issue for me. Who new it was in there?

  • Ho do I repeat an event monthly but on a specific day of the week?

    I need to repeat an event every month on the 3rd Wednesday of the month. The only monthly repeating option that I see will put it on that same day every month, by the date and not by the day of the week. Anybody know how I do this?

    Make your event on eg 20th Feb. Edit it, select Repeat/Custom , select Monthly, and 3rd Wednesday will be a selectable option.
    AK

  • Days of the Week/Months are listed as numbers

    My computer has recently been updated and rebooted, and since then my iCal has displayed the date, days of the week, etc differently.  iCal does not display any months or days of the week- they are simply just numbers.  I haven't been able to see that this is a setting- can anyone help? Thanks!

    Icheney,
    1. Open System Preferences...>Language & Text>Formats>Region: and set/re-set the appropriate region.
    2. Find and resolve duplicate fonts with Mac 101: Font Book

  • How to get the First day in a Week in a Fiscal Year

    Hi guys,
    I have a Requirement to calculate the First day in  a Week  in a Fiscal year .
    The FM GET*FIRST_DATE and all are for Calender year.
    Is there any FM to calculate the First in a Week in a Fiscal year.
    For eg. They will give 200826.
    In this 26 is the Week.
    I need to find the First date value in that Week.
    Thanks,
    Gokul

    Hi Gokul...
    Instead of using the funtion module you can just write the 3 statements of code to get the first day of the week.
    Its similar to the above one but instead of writing case statement you can achive the following.
    data : w_res type i,
             w_data type d,
    w_res = w_date mod 7.
    w_date = w_date - w_res.
    write w_date.
    This works.
    Regards,
    Siddarth

  • Calculation of MONTHS , YEARS , & DAYS between two dates

    Hi Experts,
      Currently i am using this functional Module. which calculates the number of months between two dates.
       CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
             EXPORTING
                  I_DATE_FROM = ITAB_PER-BEGDA
                  I_DATE_TO   = ITAB_PER-ENDDA
             IMPORTING
                  E_MONTHS    = CMONTHS.
      BUT this functional module Rounding off the Month...Say ..if the total numbr of days between from & to date is 105 it is showing as 4 months ...
      <b>Is there any other Functional Module</b> ????which Calculates the EXACT MONTH between two dates...(in the above case the month is expected to be 3 only since it is 105 days only)..
      Kindly help me regarding this....

    lakshimiraja,
    You can use this function module.
    report zrich_0003
           no standard page heading.
    data: duration_in_months type i.
    parameters: s_date type sy-datum,
                e_date type sy-datum.
    call function 'DURATION_DETERMINE'
    exporting
       unit                             = 'MON'
       factory_calendar                 = 'P6'    "  Your factory calendar
    importing
       duration                         = duration_in_months
    changing
       start_date                       = s_date
       end_date                         = e_date
    exceptions
       factory_calendar_not_found       = 1
       date_out_of_calendar_range       = 2
       date_not_valid                   = 3
       unit_conversion_error            = 4
       si_unit_missing                  = 5
       parameters_not_valid             = 6
       others                           = 7.
       write:/ duration_in_months.
    Don't forget to reward if useful...

  • 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;
        }

  • How can I calculate a day of a week?

    I want to calculate a day of a week.But I always getting ArraysOutOfBoundException.Here's my code:
    import java.util.*;
    import javax.swing.*;
    class daydate{
         public static void main(String args[])throws Exception
         String arr[]={
              "satarday","sunday","monday","tuesday","wednesday","thursday","friday"
    String output="",op="",m,m1,m2;
         Calendar calendar=Calendar.getInstance();
         int i=calendar.get(Calendar.DAY_OF_WEEK);
    /*if(i>6)
         i=i-7;*/
    // System.out.println(i);
         output+="\ntoday is :"+arr[i]+"\n";
         JOptionPane.showMessageDialog(null,output,"day",JOptionPane.INFORMATION_MESSAGE);
         m=JOptionPane.showInputDialog("Enter year.");
         int n=Integer.parseInt(m);
    m1=JOptionPane.showInputDialog("Enter month.");
         int n1=Integer.parseInt(m1);
         m2=JOptionPane.showInputDialog("Enter date.");
         int n2=Integer.parseInt(m2);
    calendar.set(n,n1,n2);
    int j=calendar.get(Calendar.DAY_OF_WEEK);
    /*if(j>6)
    j=j-7;*/
    //System.out.println(j);
    op+="\nthat day is/was :"+arr[j]+"\n";
         JOptionPane.showMessageDialog(null,op,"day",JOptionPane.INFORMATION_MESSAGE);
    System.exit(0);
    the error is:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
         at CalculateDay.main(CalculateDay.java:28)
    I wonder using calendar.get(Calendar.DAY_OF_WEEK) makes the value of i=7;But my array's highest value is 6.That's why I always get the above error.
    How can I solve that?

    I think the DAY_OF_WEEK is working from 1 to 7, and
    Saturday, on my PC (UK GregorianCalendar) is 7. Your
    array is based 0, and only work from (0-6).
    Either subtract 1 from the value DAY_OF_WEEK, or add
    a blank item at the beginning of the list.
    Better, I think is used the built-in capability using
    public String getDate(String format){
    Calendar c = new GregorianCalendar();
    Date d = cal.getTime();
    DateFormat df = new SimpleDateFormat(format);
    return df.format(d);
    You can then call the getDate() with various formats
    ie.
    getDate("EEE") alone to get "Wed, Thur" .. etc
    getDate("dd/MM/yyyy HH:mm:ss") to get the current
    Date and time in that format.
    Hope it helps.Thanks William for your valuable help.Anyway,you wrote,
    Date d=cal.getTime();
    Is it cal or c?

  • 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

Maybe you are looking for