Get First and last day of Month..

Hi Friends,
I am trying to fetch First and Last day of a month and would like to implement that in the following code:
SELECT COALESCE(Date_A, Date_B, Date_C)
FROM dual
Here Date A and B are in Format of MM DD YYYY (March 14, 2008)
and Date C is like MM YYYY (March 2008)
How can I get the Date_C as March 1, 2008 OR March 31, 2008 format if Date A and B are NULL ?
Thanks!
Edited by: user11095386 on Apr 23, 2009 10:45 AM

Hi,
In my earlier message, I thought that you were starting with strings like '03 12 2009' and that you wanted to display them as 'March 12 2009'. If what you have is just the reverse, then just reverse the format strings in my first message. Add a comma, if you want one, in the appropriate format string.
I believe this is what you want:
COALESCE ( TO_CHAR ( TO_DATE ( Date_A, 'fmMonth DD YYYY'), 'MM DD YYYY')
         , TO_CHAR ( TO_DATE ( Date_B, 'fmMonth DD YYYY'), 'MM DD YYYY')
         , TO_CHAR ( TO_DATE ( Date_C, 'fmMonth YYYY'),    'MM DD YYYY')
         )Notice how, on the 3rd line, TO_DATE is called without DD in the format string:
TO_DATE ( Date_C, 'fmMonth YYYY')When you do this, the day defaults to the 1st of the month, so this is all you have to do to convert the VARCHAR2 'March 2009' to the DATE 01-Mar-2009.
If you want the last day of the month, not the first, when Date_C is chosen, then use LAST_DAY:
COALESCE ( TO_CHAR ( TO_DATE ( Date_A, 'fmMonth DD YYYY'), 'MM DD YYYY')
         , TO_CHAR ( TO_DATE ( Date_B, 'fmMonth DD YYYY'), 'MM DD YYYY')
         , TO_CHAR ( LAST_DAY ( TO_DATE ( Date_C
                                          , 'fmMonth YYYY'
             , 'MM DD YYYY'
         )

Similar Messages

  • Get first and last day given month name with combobox

    hi guys ;
    I loaded to month name in combobox and I want to get first and last day by the name of month from selected Combobox
    So if I select to february than results get 01.02.2015 and 28.02.2015
    if select March than 01.03.2015 and 31.03.2015
    Thanks .

    Thank you for useful post , How to change Culturinfo as a Turkish Month name ?
    your's code is work if I use English month name But it was get error when use the turkish month name
    If you are running your application on a Turkish Windows you could use the System.Globalization.CultureInfo.CurrentCulture:
    int month = DateTime.ParseExact(monthName, "MMMM", System.Globalization.CultureInfo.CurrentCulture).Month;
    Or you could use create an explicit culture object like this:
    System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("tr-TR");
    int month = DateTime.ParseExact(monthName, "MMMM", ci).Month;
    Please remember to mark all helpful posts as answer to close your threads.

  • Get first and last date of month

    Hi,
      Is there any function module to get first and last date of month for a entered date.
    Please let me know.
    Regards,
    SP

    Hi,
    Use the below FM to find the Last day of month and them u can easily calculate the first day.
    DATA : v_startdate TYPE sy-datum.
    DATA : v_enddate TYPE sy-datum.
    DATA : v_temp TYPE dats.
    v_temp = sy-datum.
    CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
        EXPORTING
          day_in            = v_temp
        IMPORTING
          last_day_of_month = v_enddate
    CONCATENATE  v_enddate+0(6)  '01'  INTO  v_startdate.
    Hope it helps.
    Regards,
    Arnab.

  • Getting first and last day of week

    Dear all .
    Is there any funcion module which gives first and last day of the current week .
    Eg . todays day is 15.11.2006
    start date of week : 13.11.2006
    end date of week : 19.11.2006
    in the same way I want how many days are there in month .
    Eg : for Nov month :
             30 days .
          for dec month 31 days .
    Thank you in advance

    Use FM GET_WEEK_INFO_BASED_ON_DATE
    Import parameters               Value    
    DATE                            15.11.2006
                                                                                    Export parameters               Value    
    WEEK                            200646   
    MONDAY                          13.11.2006
    SUNDAY                          19.11.2006
    Use FM HR_E_NUM_OF_DAYS_OF_MONTH
    Import parameters               Value     
    P_FECHA                         15.11.2006                                                                               
    Export parameters               Value     
    NUMBER_OF_DAYS                    30        
    I hope it helps.
    Best Regards,
    Vibha
    *Please mark all the helpful answers

  • Get first and last day of the year

    and razm.date >= to_date('01.01.'||:VDATE||'', 'dd.mm.yyyy') AND razm.date <= to_date('31.12.2010.'||:VDATE||'', 'dd.mm.yyyy');
    but i get:
    ORA-01830: date format picture ends before converting entire input string
    01830. 00000 - "date format picture ends before converting entire input string"
    *Cause:   
    *Action:
    :VDATE is input param like 2010. I need to get data from range 1.1.2001 to 31.12.2010
    thx

    user13256715 wrote:
    and razm.date >= to_date('01.01.'||:VDATE||'', 'dd.mm.yyyy') AND razm.date <= to_date('31.12.2010.'||:VDATE||'', 'dd.mm.yyyy');ur making mistake in
    to_date('31.12.2010.'||:VDATE||'', 'dd.mm.yyyy');change it to
    to_date('31.12.'||:VDATE||'', 'dd.mm.yyyy');

  • How to find first and last day of last month?.

    Hello,
    I am using Crystal Report XI.
    Reports will be generated on first of every month for
    previous month. I want to find start and end date of previous month
    dynamic.
    For august, Start date is July 1st and End date July 31st.
    For September, start date is Aug 1st and Aug 31st.
    How can i get first of previous month as start date and last
    day of the previous month as end date?.
    Same kind of thing I want to do for future report ..find next
    month start date and end date.
    Thanks

    Adomacro,
    you could do a function, like this
    <cffunction name="getReportdates" returntype="struct"
    hint="Given an arbitrary month and year, the function returns a
    structure containing the first and last day of the previous
    month">
    <!--- Take current month and current year as the default
    --->
    <cfargument name="mnth" type="string" required="No"
    default="#monthAsString(month(now()))#">
    <cfargument name="yr" type="numeric" required="No"
    default="#year(now())#">
    <cfset firstDayOfGivenMonth = parseDateTime("1 " &
    arguments.mnth & " #arguments.yr#")>
    <cfset lastDayOfPreviousMonth =
    dateAdd("d",-1,firstDayOfGivenMonth)>
    <cfset numberOfDaysOfPreviousMonth =
    daysInMonth(lastDayOfPreviousMonth)>
    <cfset firstDayOfPreviousMonth =
    dateAdd("d",-#numberOfDaysOfPreviousMonth#,firstDayOfGivenMonth)>
    <cfset reportDates = structNew()>
    <cfset reportDates.firstDayOfPreviousMonth =
    firstDayOfPreviousMonth>
    <cfset reportDates.lastDayOfPreviousMonth =
    lastDayOfPreviousMonth>
    <cfreturn reportDates>
    </cffunction>
    <!--- Example usage --->
    <p>
    Given month: <strong>March
    2004</strong><br>
    begin date:
    <cfoutput>#dateFormat(getReportdates('March',2004).firstDayOfPreviousMonth,"d
    mmm yyyy")#</cfoutput><br>
    end date:
    <cfoutput>#dateFormat(getReportdates('March',2004).lastDayOfPreviousMonth,"d
    mmm yyyy")#</cfoutput><br>
    </p>
    <p>
    Given month: <strong>August
    2007</strong><br>
    begin date:
    <cfoutput>#dateFormat(getReportdates('August',2007).firstDayOfPreviousMonth,"d
    mmm yyyy")#</cfoutput><br>
    end date:
    <cfoutput>#dateFormat(getReportdates('August',2007).lastDayOfPreviousMonth,"d
    mmm yyyy")#</cfoutput><br>
    </p>

  • Getting first and last dates of a month

    Jello all,
    I am really sorry I am posting this topic here, not actually owned by this forum but in fundamental forum i am not getting it attended.
    I am generating monthly, quartelry and yearly reports, for which I need to get first and last dates of a given Month taking in to account leap year. I searched the API and docs for Calendar class. I could not find any useful methods / fields. I wonder this being a very common requirement, how SUN has not provided these essential features. I still feel, it must be some where. Please help me and reply. Also if you came across any other forum for util package, let me know.
    Thanks
    Varde

    Jello all,
    I am really sorry I am posting this topic here, not
    actually owned by this forum but in fundamental forum
    i am not getting it attended.
    Yes, and I can see you are a very patient person, waiting a whole half hour for a response before cross posting other boards.
    Question answered.
    http://forum.java.sun.com/thread.jsp?thread=514908&forum=31&message=2451646

  • Error: ORA-01847: day of month must be between 1 and last day of month

    Hi,
    I am getting this ORA-01847: day of month must be between 1 and last day of month type of error but I have checked my data all are correct.
    I am inserting the data in the merge query. It is giving the above error.
    but when i insert the data like that
    insert into dt(start_date) select TO_DATE (tariff_start_date, 'DD/MM/RRRR') from ext_zpp0a871;
    It does not give any error.
    Please find the below code
    DECLARE
    l_sv_error_msg VARCHAR2 (1000);
    BEGIN
    FOR i IN (SELECT condition_type, sales_org, division_channel, division,
    price_list, ean_upc, amount, unit_of_measure1,
    tariff_start_date, tariff_end_date
    FROM ext_zpp0a871--This is external table
    WHERE condition_type = 'ZPP0' AND ROWNUM < 200)
    LOOP
    BEGIN
    MERGE INTO sap_tariff st
    USING (SELECT i.price_list pl, i.ean_upc upc,
    TO_DATE (i.tariff_start_date, 'DD/MM/RRRR') tsd,
    TO_DATE (i.tariff_end_date, 'DD/MM/RRRR') ted
    FROM DUAL) du
    ON (st.prod_ean_cuni = du.upc
    AND st.pricelist = du.pl
    AND st.tariff_start_date = du.tsd
    AND st.tariff_end_date = du.ted)
    WHEN MATCHED THEN
    UPDATE
    SET st.condition_type = i.condition_type,
    st.sales_org = i.sales_org,
    st.division_channel = i.division_channel,
    st.division = i.division,
    st.amount =
    TO_NUMBER (REPLACE (REPLACE (i.amount, '.', NULL),
    st.uom = i.unit_of_measure1
    WHEN NOT MATCHED THEN
    INSERT (condition_type, sales_org, division_channel, division,
    pricelist, prod_ean_cuni, amount, uom,
    tariff_start_date, tariff_end_date)
    VALUES (i.condition_type, i.sales_org, i.division_channel,
    i.division, i.price_list, i.ean_upc,
    TO_NUMBER (REPLACE (REPLACE (i.amount, '.', NULL),
    i.unit_of_measure1,
    TO_DATE (i.tariff_start_date, 'DD/MM/RRRR'),
    TO_DATE (i.tariff_end_date, 'DD/MM/RRRR'));
    /*INSERT INTO sap_tariff
    (condition_type, sales_org, division_channel,
    division, pricelist, prod_ean_cuni,
    amount,
    uom,
    tariff_start_date,
    tariff_end_date
    VALUES (i.condition_type, i.sales_org, i.division_channel,
    i.division, i.price_list, i.ean_upc,
    TO_NUMBER (REPLACE (REPLACE (i.amount, '.', NULL),
    i.unit_of_measure1,
    TO_DATE (i.tariff_start_date, 'DD/MM/RRRR'),
    TO_DATE (i.tariff_end_date, 'DD/MM/RRRR')
    EXCEPTION
    WHEN DUP_VAL_ON_INDEX
    THEN
    UPDATE sap_tariff
    SET condition_type = i.condition_type,
    sales_org = i.sales_org,
    division_channel = i.division_channel,
    division = i.division,
    amount =
    TO_NUMBER (REPLACE (REPLACE (i.amount, '.', NULL),
    uom = i.unit_of_measure1;
    WHEN OTHERS
    THEN
    l_sv_error_msg := SQLERRM (SQLCODE);
    INSERT INTO sap_tariff_log
    (date_of_load, condition_type, sales_org,
    division_channel, division, price_list,
    prod_ean_cuni, amount, uom,
    tariff_start_date, tariff_end_date,
    rejection_reason
    VALUES (SYSDATE, i.condition_type, i.sales_org,
    i.division_channel, i.division, i.price_list,
    i.ean_upc, i.amount, i.unit_of_measure1,
    i.tariff_start_date, i.tariff_end_date,
    l_sv_error_msg
    END;
    END LOOP;
    COMMIT;
    EXCEPTION
    WHEN OTHERS
    THEN
    l_sv_error_msg := SQLERRM (SQLCODE);
    neo_pro_log ('Others Error', l_sv_error_msg);
    END;

    user13400510 wrote:
    but when i insert the data like that
    insert into dt(start_date) select TO_DATE (tariff_start_date, 'DD/MM/RRRR') from ext_zpp0a871;
    It does not give any error.Maybe the error is on tariff_end_date instead of tariff_start_date ?
    What are the datatypes of tariff_start_date and tariff_end_date ? If they are already dates, and you to_date them (and depending on what your nls_date_xxxxx params are) you can have such errors :SQL> sho parameter nls_date_format
    NAME_COL_PLUS_SHOW_PARAM                 TYPE        VALUE_COL_PLUS_SHOW_PARAM
    nls_date_format                          string      DD/MM/YYYY
    SQL> select to_date(sysdate,'Day dd Mon RRRR') from dual;
    select to_date(sysdate,'Day dd Mon RRRR') from dual
    ERROR at line 1:
    ORA-01846: not a valid day of the week
    SQL> select to_date(sysdate,'hh24:mi:ss dd/mm/rrrr') from dual;
    select to_date(sysdate,'hh24:mi:ss dd/mm/rrrr') from dual
    ERROR at line 1:
    ORA-01850: hour must be between 0 and 23

  • ORA-01847: day of month must be between 1 and last day of month error

    Hi All
    When i run the following code i'm getting the error:ORA-01847: day of month must be between 1 and last day of month error
    SELECT t2.owner_cat,
    t1.owner_id,
    stock_id,
    Sum(received_amount) received_amount,
    Sum(curr_amount) curr_amount,
    Sum(used_amount) used_amount,
    To_char(Add_months(date_work,6),'YYYY') date_work
    FROM (SELECT owner_id_to owner_id,
    stock_id_to stock_id,
    Sum(full_amount) received_amount,
    0 curr_amount,
    0 used_amount,
    To_char(0) date_work
    FROM dw_wms_mat_transfer
    WHERE master_code_id IN ('8664','8665')
    GROUP BY owner_id_to,
    stock_id_to
    UNION ALL
    SELECT owner_id,
    stock_id,
    0 received_amount,
    Sum(curr_amount) curr_amount,
    0 used_amount,
    To_char(0) date_work
    FROM dw_wms_mat_inv
    WHERE master_code_id IN ('8664','8665')
    GROUP BY owner_id,
    stock_id
    UNION ALL
    SELECT t2.owner_id,
    t1.stock_id,
    0 received_amt,
    0 curr_amt,
    Sum(amount) used_amt,
    To_char(Add_months(date_work,6),'YYYY') date_work
    FROM dw_wms_wo_mat_dc t1,
    (SELECT owner_id,
    stock_id
    FROM dw_wms_mat_inv
    WHERE master_code_id IN ('8664','8665')
    GROUP BY owner_id,
    stock_id) t2
    WHERE t1.stock_id = t2.stock_id
    GROUP BY t2.owner_id,
    t1.stock_id,
    To_char(Add_months(date_work,6),'YYYY')) t1,
    dw_wms_setup_owner t2
    WHERE t1.owner_id = t2.owner_id
    GROUP BY t2.owner_cat,
    t1.owner_id,
    stock_id,
    To_char(Add_months(date_work,6),'YYYY')
    But when i just run the inner query:
    (SELECT owner_id_to owner_id,
    stock_id_to stock_id,
    Sum(full_amount) received_amount,
    0 curr_amount,
    0 used_amount,
    To_char(0) date_work
    FROM dw_wms_mat_transfer
    WHERE master_code_id IN ('8664','8665')
    GROUP BY owner_id_to,
    stock_id_to
    UNION ALL
    SELECT owner_id,
    stock_id,
    0 received_amount,
    Sum(curr_amount) curr_amount,
    0 used_amount,
    To_char(0) date_work
    FROM dw_wms_mat_inv
    WHERE master_code_id IN ('8664','8665')
    GROUP BY owner_id,
    stock_id
    UNION ALL
    SELECT t2.owner_id,
    t1.stock_id,
    0 received_amt,
    0 curr_amt,
    Sum(amount) used_amt,
    To_char(Add_months(date_work,6),'YYYY') date_work
    FROM dw_wms_wo_mat_dc t1,
    (SELECT owner_id,
    stock_id
    FROM dw_wms_mat_inv
    WHERE master_code_id IN ('8664','8665')
    GROUP BY owner_id,
    stock_id) t2
    WHERE t1.stock_id = t2.stock_id
    GROUP BY t2.owner_id,
    t1.stock_id,
    To_char(Add_months(date_work,6),'YYYY'))
    I'm not getting that error, any help please?

    Hi,
    Like Anuraq already explained, you need to keep in mind that when you apply a to_char, you've turned your DATE datatype into a STRING and by doing that you've lost the ability to use the add_months function again in your outer query.
    Using a simplified example, extracted from your example:
    MHO%xe> select to_char(add_months(date_work, 6), 'yyyy') date_work
      2  from ( select to_char(0) date_work
      3         from dual
      4         union all
      5         select to_char(0) date_work
      6         from dual
      7         union all
      8         select to_char(add_months(sysdate, 6), 'yyyy') date_work
      9         from dual
    10       );
    select to_char(add_months(date_work, 6), 'yyyy') date_work
    FOUT in regel 1:
    .ORA-01847: day of month must be between 1 and last day of monthHowever, you should either do something like:
    MHO%xe> select nvl(to_char(add_months(date_work, 12), 'yyyy'), '0') date_work
      2  from ( select to_date(null) date_work
      3         from dual
      4         union all
      5         select to_date(null) date_work
      6         from dual
      7         union all
      8         select sysdate date_work
      9         from dual
    10       );
    DATE
    0
    0
    2010or (less clear, more confusing):
    MHO%xe> select nvl(to_char(add_months(date_work, 6), 'yyyy'), '0') date_work
      2  from ( select to_date(null) date_work
      3         from dual
      4         union all
      5         select to_date(null) date_work
      6         from dual
      7         union all
      8         select add_months(sysdate, 6) date_work
      9         from dual
    10       );
    DATE
    0
    0
    2010It's not clear to me why you're using add_months twice (inner + outer query) in your original example.
    As you can see you can get the same results using it only once in your outer query.

  • Find the first and last day of week giving a certain date

    Hi,
    i have an application in wich the user puts a date, say today 2010-08-10 and i have to calculate first and last day of that week, in this case 2010-08-09 and 2010-08-15. How can i do this?
    Many thanks in advance,
    Nuno Almeida

    nfalmeida wrote:
    i have an application in wich the user puts a date, say today 2010-08-10 and i have to calculate first and last day of that week, in this case 2010-08-09 and 2010-08-15. How can i do this?First step is being sure that you know what a 'week' is.
    For example does it really start on monday? And will it always start on monday?
    And what day does the 'week' end on for 2010-12-29? In some businesses it will end on 2010-12-31 (friday)

  • How to find first and last day of previous month?.

    Based on current month, I want to find start and end day of
    previous month.
    For example,
    For august, Start date is July 1st and End date July 31st.
    How can i get first of previous month as start date and last
    day of the previous month as end date?.
    Same way,
    i want to find start date of current month and end date of
    next month.
    Example:
    For august,
    i want to get start date, august 1st and end date : september
    30.
    How can i do this from current date or now().
    I am looking for best and easy way to find start and end
    dates..
    Thanks

    <cfset today = now()>
    <cfset firstOfThisMonth = createDate(year(today),
    month(today), 1)>
    <cfset lastOfNextMonth = dateAdd("d", -1, dateAdd("m", 2,
    firstOfThisMonth))>
    <cfoutput>
    today = #today#<br>
    firstOfThisMonth = #firstOfThisMonth#<br>
    lastOfNextMonth = #lastOfNextMonth#<br>
    </cfoutput>
    Edit - To find the start and end day of previous month, get
    the first of THIS month. Use Subtract 1 month ("m") to get the
    start date. Subtract 1 day ("d") to get the end date.

  • How to get first and last date of previous month

    To set default values in selection screen,I want first and last date of the previous month.
    Also I want the first and last dates of previous quarter.
    The quarters can be only january to march, apr to june, jul to sept, oct to dec.
    I want to run a program on beginning of each month by job scheduling having <b>selection screens</b> for the above monthly and quarterly dates.

    Hi Suhas,
    Use the below code.
    DATA: v_date LIKE sy-datum.
    DATA: v_month_begin_date TYPE sy-datum,
          v_month_end_date TYPE sy-datum,
          v_month(2) TYPE n,
          v_month1(2) TYPE n,
          v_quarter TYPE i,
          v_year(4) TYPE n,
          v_quarter_begda TYPE sy-datum,
          v_quarter_endda TYPE sy-datum.
    v_month =  sy-datum+4(2).
    IF v_month = '01'.
      v_month = '12'.
      v_year = sy-datum+0(4) - 1.
    ELSE.
      v_month = v_month - 1.
      v_year = sy-datum+0(4).
    ENDIF.
    CONCATENATE v_year v_month  '01' INTO v_date.
    CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
      EXPORTING
        iv_date             = v_date
      IMPORTING
        ev_month_begin_date = v_month_begin_date
        ev_month_end_date   = v_month_end_date.
    v_month1 = sy-datum+4(2).
    IF v_month1 = '01' OR
       v_month1 = '02' OR
       v_month1 = '03'.
      v_quarter = 1.
    ELSEIF v_month1 = '04' OR
           v_month1 = '05' OR
           v_month1 = '06'.
      v_quarter = 2.
    ELSEIF v_month1 = '07' OR
           v_month1 = '08' OR
           v_month1 = '09'.
      v_quarter = 3.
    ELSEIF v_month1 = '10' OR
           v_month1 = '11' OR
           v_month1 = '12'.
      v_quarter = 4.
    ENDIF.
    IF v_quarter = 1.
      v_quarter = 4.
      v_year = sy-datum+0(4) - 1.
    ELSE.
      v_quarter = v_quarter - 1.
      v_year = sy-datum+0(4).
    ENDIF.
    CALL FUNCTION 'HR_99S_GET_DATES_QUARTER'
      EXPORTING
        im_quarter = v_quarter
        im_year    = v_year
      IMPORTING
        ex_begda   = v_quarter_begda
        ex_endda   = v_quarter_endda.
    WRITE:/5 'previous month begin date : ', v_month_begin_date.
    WRITE:/5 'previous month end date   : ', v_month_end_date.
    WRITE:/5 'previous quarter begin date : ', v_quarter_begda.
    WRITE:/5 'previous quarter end date : ', v_quarter_endda.
    Message was edited by:
            Velangini Showry Maria Kumar Bandanadham

  • Day must be between 1 and last day of month

    Hi
    I have a master detail form for overtime entries.
    Master Block contain emp_no,name,month etc.
    Detail block contain a date field ,,from time, to time etc
    when i enter the date in detail block it defaults the month from Server date and i am getting the error "Day must be between 1 and last day of ...."
    The form is going to reside on server so i cant go for changing system date for that.
    THe work around i am trying is i have created a dummy item in detail block for Date(dd) entry and populating my original date field on the basis of it.
    so that i can get rid of last day validation of month.The datatype of dummy item is char
    my code is
    c_day varchar(2);
    c_month varchar(2);
    c_year varchar(4);
    d_date varchar(8);
    begin
    c_day := :DETAIL.dummy;
    c_month := to_char(:MASTER.month, 'mm');
    c_year := to_char(:master.month, 'yyyy');
    d_date := c_day||c_month||c_year;
    :DETAIL.ot_date := to_date(d_date,'ddmmyyyy');
    end;
    I am using post change trigger on my dummy item but i am getting ORA-01840 for that.I have tried several ways but it is giving different type of date errors for that.
    Any help is highly appreciated

    Dear try this
    SELECT RUN_NUM, CV AS MONTH_DATE
    FROM
    SELECT ROWNUM AS RUN_NUM,TO_DATE('01-' || 'SEP' || '-' || 2007 ,'DD/MM/YYYY')+ (ROWNUM-1) CV
    FROM
    (SELECT 1 FROM DUAL GROUP BY CUBE (1,1,1,1,1)) A
    WHERE TO_CHAR(CV,'MON-YYYY') = 'SEP-2007'

  • To get first day and last day of month.

    Please help, I need a sql function that will return the first day of a month when I enter a date that is on or before the 15th and then returns the last day of the month when I enter a date of the 16th or later.
    This is my query but I get ORA-00932: inconsistent datatypes: expected DATE got CHAR error.
    select CASE
    WHEN to_char(:p_date, 'DD') < 15 THEN
    add_months((LAST_DAY(:p_date)+1), -1)
    WHEN to_char(:p_date, 'DD') > 15 THEN
    TO_CHAR(LAST_DAY(:p_date))
    end
    from dual;
    Thanks

    Hi,
    please use the good habit to mark your questions as answered when you are satisfied with the answers.
    Additionally when you put some code or output please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • First and last day of current year as a date object

    Howdy...
    can someone please help me out... i need a fast way to get the first day of the current year as a date object and the last day of the current year as a date object...
    big thanks for any sample code...

    import java.util.Calendar;
    // snip
    Calendar firstDayOfYear = Calendar.getInstance(); // will initialize it with today
    firstDayOfYear.set(Calendar.DAY_OF_MONTH, 1);
    firstDayOfYear.set(Calendar.MONTH, Calendar.JANUARY);
    Calendar lastDayOfYear = Calendar.getInstance(); // will initialize it with today
    lastDayOfYear.set(Calendar.DAY_OF_MONTH, 31);
    lastDayOfYear.set(Calendar.MONTH, Calendar.DECEMBER);Rommie.

Maybe you are looking for