Finding days in a specific month

Hi All,
I need help in writing a query to retrieve all days in a specific month using sysdate.
For eaxmple
SELECT trunc(to_date(sysdate, 'DD-MONTH-RRRR')
FROM DUAL
WHERE sysdate between FIRST_DAY AND LAST_DAY;

select trunc(sysdate,'month')+n-1
from (select rownum n
      from dual
      connect by level <= (last_day(sysdate)-trunc(sysdate,'month')+1));
Message was edited by:
        jeneesh                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Find the difference between two dates for the specific month and year

    Hi,
    I have two dates, start date is 30/12/2012 and end date is 04/01/2013. Using datediff I found the difference of days between two dates. But I find the no of days in January 2013. ie output is 4 instead of 6. I input month and year to find the no of days
    for that date. In this case I input Jan 2013. How can I sql this ?

    I don't understand how most of the answers provided here not analytically solving the problem with many cases possible.
    First let me understand you:
    You have 2 dates range and you want to calculate day range for specific month and year between the original date range.
    declare @for_month int = 1 --January
    declare @for_year int = 2013
    declare @StartDate date = '2012-12-20'
    declare @EndDate date = '2013-01-04'
    SELECT
    CASE
    WHEN (DATEPART(MONTH, @StartDate) = @for_month and DATEPART(MONTH, @EndDate) = @for_month) and ((DATEPART(YEAR, @StartDate) = @for_year or DATEPART(YEAR, @EndDate) = @for_year)) THEN
    DATEDIFF(DAY, @StartDate,@EndDate)
    WHEN (@StartDate < cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (@EndDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
    DATEDIFF(DAY, DATEADD(MONTH, DATEDIFF(MONTH, -1, @EndDate)-1, 0),@EndDate)
    WHEN (@EndDate > cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) and (@StartDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
    DATEDIFF(DAY, @StartDate,DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @StartDate) + 1, 0))) + 1
    WHEN ((DATEDIFF(DAY, @StartDate, cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) >= 0) and (DATEDIFF(DAY, cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date), @EndDate) >= 0)) THEN
    DATEDIFF(DAY, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime), DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime)) + 1, 0))) + 1
    ELSE
    0
    END as [DD]
    I don't know how you calculate day range between 01/01/2013 and 04/01/2013
    is 4, it is actually is 3 but if that is the case, you can add 1 from the condition.

  • Finding date,day of the whole month

    dear members,
    can i find the date, day of a specific month in a query. Is there any default functionality, or built-in.
    e.g. select date,day
    from .........
    where month='JAN';
    date day
    01-01-2011 sunday
    02-01-2011 monday
    31-01-2011 tuesday
    thanks.
    teefu.

    Dear,
    There is someone here in this otn site who wrote a very nice sql script which gives a kind of calendar. I have sligthly updated his script as follows
    with x
               as (
            select *
              from (
            select to_char(trunc(to_date('01062011','ddmmrrrr'),'mm')+level-1,'iw') wk,
                  to_char(trunc(to_date('01062011','ddmmrrrr'),'mm')+level-1,'dd') dm,
                  to_number(to_char(trunc(to_date('01062011','ddmmrrrr'),'mm')+level-1,'d')) dw,
                  to_char(trunc(to_date('01062011','ddmmrrrr'),'mm')+level-1,'mm') curr_mth,
                  to_char(to_date('01062011','ddmmrrrr'),'mm') mth
            from dual
           connect by level <= 31
           where curr_mth = mth
          select max(case dw when 2 then dm end) Monday,
                 max(case dw when 3 then dm end) Tuesday,
                 max(case dw when 4 then dm end) Wednesday,
                 max(case dw when 5 then dm end) Thursday,
                 max(case dw when 6 then dm end) Friday,
                 max(case dw when 7 then dm end) Saturday,
                 max(case dw when 1 then dm end) Sunday
            from x
           group by wk
           order by wkSorry I didn"t find the original post in which this sql has been initially posted
    Hope this helps
    Mohamed Houri

  • I like and use Top Sites but it has become unsuable with this constant blacking out and reloading the thumbnails.  My MBP has not seen a problem at all.   I have been searching every other day for over a month trying to find a fix in Windows Safari with n

    I like and use Top Sites but it has become unsuable with this constant blacking out and reloading the thumbnails.  My MBP has not seen a problem at all.
    I have been searching every other day for over a month trying to find a fix in Windows Safari with no joy.  I want to resolve, not switch browsers. Please offer up a solution that only refreshes the Top Site thumbnails once a day or as some controlable interval.  Started about two versions ago, now on ver 5.1.5. Windows 7 64bit.
    Safari 5.1.5 for Win64 bit, Windows 7!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    I think I solved the wifi connection problem, just by switching off completely the router! sounds trivial, but in this case it worked!!!
    the funny behaviour of the trackpad/cursor still persists. any suggestion???
    thanks again

  • Need to find the last day of the previous month

    hi folks,
    the code goes like this...
    data: xt247 type t247,
          monthn(30) type c,
          monthnumber type i,
          bforwardmonth type i.
    call function 'RP_LAST_DAY_OF_MONTHS'
      EXPORTING
        day_in            = s_date
      IMPORTING
        last_day_of_month = e_date.
    write: 'The last day of the month', e_date.
    select single * from t247 into xt247
            where spras = sy-langu
              and mnr = e_date+4(2).
    monthnumber = xt247-mnr.
    write:' The month number', monthnumber.
    determine the previous month.
    bforwardmonth = monthnumber - 1.
    From here I need to determine the last day of the previous month How can I do?
    Thanks for your help.
    Santhosh

    Hi all,
    here's the shortest solution:
    REPORT z123.
    PARAMETERS p_datum LIKE sy-datum DEFAULT sy-datum.
    DATA ultimo  LIKE sy-datum.
    <b>ultimo = p_datum - p_datum+6(2).</b>
    WRITE: / p_datum, 20 ultimo COLOR 2.
    it's not my solution :
    it's from <a href="http://www.abapforum.com/forum/viewtopic.php?t=1434&highlight=ultimo">Andrew_</a>
    regards Andreas

  • Number of all Mondays to Fridays in specific month

    Hi Experts,
    How to find number of all Mondays to Fridays in specific month?
    Is the any standar FM for the same?
    regards

    Hi Ashish,
    use the below function module to count the no of weekdays(monday-friday).
    first find the first day and last day of the month..by passing any date of the monthe to below function modules..
    CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'    " returns last day of the month..
    EXPORTING
            VALUE = SY-DATUM
      IMPORTING
             VALUE = w_lastdate
    CALL FUNCTION  "RS_VARI_V_1_ACTUAL_MONTH" --Returns first day of the actual month.
      EXPORTING
            VALUE = SY-DATUM
      IMPORTING
             VALUE = w_firstdate
    do 31 times.    "max days is 31...
    if w_lastdate GE w_firstdate.
      CALL FUNCTION DATE_GET_WEEK..
           EXPORTING
                 DATE    = SCAL-DATE  "result from RP_LAST_DAY_OF_MONTHS
           IMPORTING
                 VALUE = w_WEEK.
      if w_week = 1.
         monday = monday +1.
      elseif w_week = 2.
       tuesday = tuesday + 1.
      elseif w_week = 2.
       tuesday = tuesday + 1.
      elseif w_week = 3.
       wednesday = wednesday + 1.
      elseif w_week = 4.
       thursday = thursday + 1.
      elseif w_week = 5.
       friday = friday + 1.
      endif.
      if w_week ge 1 and le 5.
       weekdays = weekdays + 1.  "counting totoal number of modays - fridays in the month
      endif.
    ELSE.
    EXIT.
    endif.
    endloop.
    DATE_GET_WEEK Returns week for a date
    if it returns 1 = monday
    2 = tuesday
    3 = wednesday
    4 = thursday
    5 = friday
    6 = saturday
    7 = sunday
    RP_LAST_DAY_OF_MONTHS
    Regards,m
    Prabhudas
    Edited by: Prabhu Das on May 13, 2009 7:49 PM

  • How to get the last day of the previous month

    Hello Team,
    If  my input date is today , then i need to find out the last day of the previous month for the same.
    Can someone help me  to find out .. how can this be done.
    Regards,
    Ravi

    Hi,
    Try the below code.
         // get a calendar object
        GregorianCalendar calendar = new GregorianCalendar();
        // convert the year and month to integers
        int yearInt = Integer.parseInt(year);
        int monthInt = Integer.parseInt(month);
         int dayInt = Integer.parseInt(day);
        // adjust the month for a zero based index
        monthInt = monthInt - 1;
        // set the date of the calendar to the date provided
        calendar.set(yearInt, monthInt, dayInt);
        int day = calendar.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
        return Integer.toString(day);
    Regards
    Venkat

  • Number of days in given date/month

    Hi,
    Can you send query to find the number of days in given date/month
    Regards,
    Venkat.

    If you want No. of days between two date then you can just Subtract them. If you want the number of days in a month you can get the first and last day of the month and subtract them.
    Solution for a month.
    SQL> with t as (select to_date('&month','mmyyyy') as dt from dual)
      2  select (last_day(dt) - trunc(dt, 'mm'))+1
      3    from t
      4  /
    Enter value for month: 012009
    old   1: with t as (select to_date('&month','mmyyyy') as dt from dual)
    new   1: with t as (select to_date('012009','mmyyyy') as dt from dual)
    (LAST_DAY(DT)-TRUNC(DT,'MM'))+1
                                 31
    SQL> /
    Enter value for month: 022009
    old   1: with t as (select to_date('&month','mmyyyy') as dt from dual)
    new   1: with t as (select to_date('022009','mmyyyy') as dt from dual)
    (LAST_DAY(DT)-TRUNC(DT,'MM'))+1
                                 28
    SQL> /
    Enter value for month: 122009
    old   1: with t as (select to_date('&month','mmyyyy') as dt from dual)
    new   1: with t as (select to_date('122009','mmyyyy') as dt from dual)
    (LAST_DAY(DT)-TRUNC(DT,'MM'))+1
                                 31Edited by: Karthick_Arp on Feb 19, 2009 9:56 PM

  • Returning  'Day' value based on month and year parameters

    Hi,
    Is there a code that would return an end of the month  Day value based on month and year parameters?
    For example if my parameters yield 9 or September for a month value and 08 or 2008 for the year value, can a formula generate a value of 30 (the last day of the given month in the specific year)?
    This way the formula would pick up the different last day of the month in February for the leap years.
    Thank you.
    Vic

    1. Open the formula workshop.
    2. From the Repository Custom Functions, under Crystal and then Date, RIGHT click on cdlastdayofmonth, click on ADD TO REPORT.
    3. Create a new formula, in the formula workshop, under FUNCTIONS, go down the list till you see "CUSTOM FUNCTIONS", expand that till you see cdlastdayofmonth.
    4. In your formula, type cdlastdayofmonth(currentdate)
    5. Save and close and display the formula in your report, you should see 11/30/2008.
    If you want just the day then modify the formula to:
    totext(day(cdlastdayofmonth(currentdate)),0,'','');
    since you have parameters for month and year, do this:
    totext(day(cdlastdayofmonth(date({?year},{?month},01))),0,'','');
    to give you the last day of the month.

  • BI Content Variable on 0Calday for first day of the fiscal year and first day of the current month

    Hi Friends,
    In one of my BEx queries, I need to restrict a key figure for 0Calday based on the first day of the current fiscal year. And another key figure for the first day of the current month. Instead of using Customer exit, I hope there is some SAP delivered standard variable for these filters.
    Please let me know if there is anything available for this. Your answers will be highly appreciated.
    Thanks & Regards,
    Ranjan

    Hi Ranjan,
    Please find below standard variables.
    Pls check below link for more.
    Standard Variables in BEX related to Time Charcteristics
    Characteristic
    Variable
    Description
    0CALDAY
    0CWD
    Current Workday (SAP Exit)
    0CALDAY
    0CYTCD
    Cumulated to Current Day (SAP Exit)
    0CALDAY
    0DAT
    Current Calendar Day (SAP Exit)
    0CALDAY
    0DAY_***
    Cumulation of all Values to Key Date (SAP-Exit)
    0CALDAY
    0LYTCLD
    Cumulated to Current Day of Previous Year
    0CALDAY
    0LYTCLD
    Previous Year Cumulated to Current Day (SAP Exit)
    0CALDAY
    0L_DATE
    Last Calendar Date
    0CALDAY
    0P_LY_R
    Comparative Period for Last Year
    0CALDAY
    0P_TY_R
    Period for Current Year up to Yesterday
    0CALDAY
    0S_KDATE
    Key Date Interval for Previous Year (SAP Exit)
    0CALDAY
    0S_KDAY
    Key Date Interval Current Year (SAP Exit)
    Best,
    SATYA.

  • In ICal is there a way to see all of the text in all day events on the month view of the calendar.  Seems to wrap text only if there is a time on the event

    In ICal is there a way to see all of the text in all day events on the month view of the calendar?  Seems to wrap text only if there is a time on the event

    The paths won't agree on the two OSs so a simple XML import isn't likely to work.
    See Sync iPod/iPad/iPhone with two computers and, if needed, Make a split library portable. The techniques in the first link will work when moving the library between Windows and OS X as long as the library is "portable", but iTunes takes quite some time checking the database when the library is opened under a different OS.
    tt2

  • Get the values from Day 1 of the Month

    Hi Friends,
    I have a requirement in which I have to Get the values from Day 1 of the Month.
    Ex : If I enter 19 - 07 - 2007.......the report should display Values from 01 - 07 - 2007.
    How to Code ?
    Please provide the Code.
    Thank you.

    Hello ,
              Check this code,
    DATA: test_datum1      LIKE sy-datum,
               test_datum2      LIKE sy-datum.
    WHEN 'TEST1'.
              IF i_step = 2.
          LOOP AT i_t_var_range INTO loc_var_range
            WHERE vnam = 'TEST2'.
            test_datum1      = loc_var_range-low.
        CONCATENATE test_datum1(6) '01' INTO  test_datum2.
        CLEAR l_s_range.
        l_s_range-low   = test_datum2.
        l_s_range-high  = test_datum1.
        l_s_range-sign = 'I'.
        l_s_range-opt  = 'BT'.
        APPEND l_s_range TO e_t_range.
    hope it helps,
    assign points if useful

  • Currency Translation based on Last Day of the Acquistion month

    Dear all,
                Request to help me in understanding how we can calculate the currency translation rate as per the last day if the acquistion month..
    For Example if the  Acquistion date : 01/01/2008 (mm/dd/yyyy) the currency translation should happend based on the rate maintained as on 31/01/2008.
    Thanks
    Pavan Kumar Prakhya

    First, you will need to convert the actual acquisition date to the end date of the Fiscal Period. This can be done by using two separate Function Modules. First, get the actual Fiscal Period by entering the date and Fiscal Year Variant into the DATE_TO_PERIOD_CONVERT Function Module. Use the Fiscal Year and Fiscal Period from this and determine the end date of the Fiscal Period by using Function Module LAST_DAY_IN_PERIOD_GET with Fiscal Year, Fiscal Period and Fiscal Year Variant as your inputs.
    For the conversion, use the Function Module CONVERT_TO_LOCAL_CURRENCY. The inputs for this would be the last date of the Fiscal Period, the amount to be converted, the from currency code, the to currency code, blank in rate, AS01 in type of rate and X in read TCURR. This assumes, however, that month-end rates (rate type = AS01) have been loaded into your source system and these rates have been transferred to your BW environment.

  • How to get the last day of the next month?

    Hi all.
    I need to get the last day of the next month. E.g. if the date is 20.03.2008 I need to get 30.04.2008.
    Is there any FM for it?
    TIA, Nikolai.

    hi Nikolai,
    pls. have a look athe following piece of code:
    PARAMETERS : p_date TYPE sy-datum.
    DATA : gv_res TYPE sy-datum.
    CALL FUNCTION 'CALCULATE_DATE'
    EXPORTING
    *   DAYS              = '0'
       months            = '2'
       start_date        = p_date
    IMPORTING
       result_date       = gv_res.
    ==> Now you have (gv_res) 2 months later as today
    gv_res+6(2) = '01'. ==> gv_res is first day of next-next month
    gv_res = gv_res - 1. ==> gv_res is last day of next month
    hope this helps
    ec

  • Can SharePoint calendar show more than 3 items on a Day's schedule in Month view? How?

    Hi there,
    Can SharePoint calendar show more than 3 items on a Day's schedule in Month view? How?
    Thank you so much.

    Hi,
    From your description, my understanding is that you want to expand all items if a Day’s schedule has more than 3 items.
    You could accomplish your requirement with jQuery to auto expand all items when you load month view, please refer to this article:
    Auto Expand Month View on SharePoint 2013 Calendar
    http://blog.eastridge.net/auto-expand-month-view-on-sharepoint-2013-calendar
    If I misunderstand your requirement, please provide more detailed information.
    Best Regards,
    Vincent Han
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

Maybe you are looking for

  • Mac Book Pro doesn't recognize Verizon Air Card

    After VZ Access Manager software is installed and the device is connected to USB, my Mac Book Pro will not recognize the device. Am I missing something here?

  • BI Input Selection Screen : Pass values

    Hi, I have a requirement where I have to show only those business partners who are assigned to a BP Role entered in another variable of the same selection screen. If the role is Sold to party I have to show only those busness partners who are assigne

  • Unable to view help

    HI , Please advise me how to activate help in SAP Screen . When i Click on (?) Help : Navigation to the webpage was canceled Occurs . How to solve this problem . Ashish Ranjan

  • Number for itunes support asap

    what is the phone number in the uk for itunes support need it asap

  • [SOLVED] zenity 3.8 broke my scripts

    After updating from zenity 3.6 to 3.8, most of my scripts dont work. A little example: #!/bin/bash title="Server Options" prompt="Pick an option:" options=("option 1" "option 2" "option 3") while opt=$(zenity --width 500 --height 300 --title="$title"