Date for first day of current month

How can i get the date for first day of current month ?

select trunc(sysdate,'MM'),to_char(trunc(sysdate,'MM'),'DD'),to_char(trunc(sysdate,'MM'),'Day') from dual;

Similar Messages

  • Date Functions( first day of a month that is 3 months from now....)

    I have recently written my first stored procedure.
    Its rather a bunch of SQL statements.
    I had to hard code lot of dates. most of them are first day of the current monthe or last day of current month etc.
    I thot of parametrizing all the dates, but if a business person has to include all the parameters they could go wrong and get the wrong results.
    Now, I want to use date functions to achieve these requirements:
    Can any one please throw some insght into this:....
    1) First day of current month,
    2) last day of current month.
    3) first day of previious month
    4) last day of previous month
    5) first day of a month that is 3 months from now.
    6) last day of a month that is 3 months from now.
    7).....
    Can any one please throw some light on any one of this.. I can try to work from there onwards ....
    Thanks a lot in advance,
    Ac

    Hi there,
    1) First day of current month
    select trunc(sysdate, 'MM') from dual;
    2) last day of current month.
    select trunc(add_months(sysdate, 1), 'MM') - 1 from dual;
    3) first day of previious month
    select trunc(add_months(sysdate, -1), 'MM') from dual;
    4) last day of previous month
    select trunc(sysdate, 'MM') - 1 from dual;
    5) first day of a month that is 3 months from now.
    select trunc(add_months(sysdate, 3), 'MM') from dual;
    6) last day of a month that is 3 months from now.
    select trunc(add_months(sysdate, 4), 'MM') - 1 from dual;cheers,
    Anthony

  • How to get the first day of current month

    hi guys,
    i am trying to get the first day of current month which get from the date i input at the selection screen. my method is not so good, so i was wondering if there is better way to get the this,
    thanks.

    Try this .
    data : DAYNR LIKE  HRVSCHED-DAYNR,
         DAYTXT LIKE  HRVSCHED-DAYTXT.
    data langu like sy-langu value 'EN'.
    Parameters PDATE LIKE SY-DATUM.
    PDATE+6(02) = '01'.
    CALL FUNCTION 'RH_GET_DATE_DAYNAME'
      EXPORTING
        LANGU                     = LANGU
        DATE                      = PDATE
      CALID                     =
    IMPORTING
       DAYNR                     = DAYNR
       DAYTXT                    = DAYTXT
      DAYFREE                   =
    EXCEPTIONS
      NO_LANGU                  = 1
      NO_DATE                   = 2
      NO_DAYTXT_FOR_LANGU       = 3
      INVALID_DATE              = 4
      OTHERS                    = 5
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    WRITE :/ PDATE, DAYNR, DAYTXT.
    Cheers

  • First day of current month, one year ago

    All,
    Does anyone have a calculation or know how I can calculate the first day of the current month, one year ago? I am trying to setup a filter criteria to show all records created >= 1st day of current month for prior year and <= the last day of the prior month. I have the second half of the equation for last day prior month but need some help on the first half.
    Thanks in advance for any pointers!
    D

    You can try:
    SELECT TRUNC(ADD_MONTHS(sysdate, -12), 'MON') FROM dual;
    Or
    SELECT TRUNC(sysdate-NUMTOYMINTERVAL(1,'YEAR'), 'MON') FROM dual;

  • Last day of previous month, first day of current month

    Hi,
    Whats the best way to calculate the last date of the previous month, and the first day of the current month.
    Thank you for your help.
    Sumit.

    Here are FMs
    SG_PS_GET_LAST_DAY_OF_MONTH    FM calculating the last day of a month                                                                               
    FVOZ                                                                               
    RE_LAST_DAY_OF_MONTH                                                                               
    HRHCP00_TIME_HANDLING                                                                               
    HR_HCP_GET_LAST_DAY_OF_MONTH                                                                               
    HRVE_REPORTING                                                                               
    HRVE_LAST_DAY_OF_MONTH                                                                               
    RPDD                           HR-D: Payroll Germany                                              
    RP_LAST_DAY_OF_MONTHS          HR-D: Determine last day of month                                                                               
    SLS0                           PAW - Miscelaneous (MISC)                                          
    SLS_MISC_GET_LAST_DAY_OF_MONTH FM calculating the last day of a month                                                                               
    VVSRCH                                                                               
    LAST_DAY_OF_MONTHS                                                                               
    BWSO_DATE_GET_FIRST_WEEKDAY     
    CKSO                            
    CK_F_GET_FIRST_DAY_OF_DATE      
    HRBEN00SPENDA                   
    HR_BEN_SPENDA_FIRST_LAST_DAY    
    HRPB                            
    HRPP_CCODE_GET_FIRSTDAY_PERIOD  
    HRVE_PAYROLL                    
    HRVE_GET_FIRST_LAST_MONDAY      
    JBT6                            
    ISB_GET_FIRST_DAY               
    KED2                            
    RKE_GET_FIRST_DAY_IN_PERIOD     
    MCP2                            
    MC_PERIOTAB_BT_FIRST_LASTDAY    
    MC_PERIO_GET_FIRST_AND_LASTDAY  
    Thanks
    SK

  • First Day of Current Month

    I need to return the first day of the current month. I have read I can use:
    WITH  MEMBER [Measures].[FirstDayOfMonth] AS 
    DateSerial(Year(Now()), Month(Now()), 1)
    However, this returns an incorrect format. Can this date member be formatted to yyyy-MM-dd?
    I have also read I can use OpeningPeriod but I could not get this to work.
    My date Hierarchy is:
    [Date].[Year Month Day].[Month]
    And my month members are in the yyy-MM-dd format, for example:
    [Date].[Year Month Day].[Month].&[2015-02-01]

    Thanks Richard,
    I am not sure what the "aa" string is for?
    Yes, I can get the current date using:
    WITH
    MEMBER [Measures].[Month Day] AS
    FORMAT(Now(), "yyyy-MM-dd")
    But I need to return the first date of the current month dynamically. For example, today this value would be: 
    [Date].[Year Month Day].[Month].&[2015-02-01]
    So I cannot use Parent or FirstChild as the hierarchy will not recognise the
    FORMAT(Now(), "yyyy-MM-dd") as a month member as it returns 2015-02-18.
    I believe I need to extract the current month day value, subtract this value from the Now() and add 1 (start of month), for example:
    StrToMember("[Date].[Year Month Day].[Month ].&[" + FORMAT(Now()-[Month Day]+1,
    "yyyy-MM-dd") +"]")
    Which will be 2015-02-18 - 18 + 1 = 2015-02-01
    Or:
    WITH
    MEMBER [Measures].[Month Day] AS
    FORMAT(Now()-[Month Day Value]+1, "yyyy-MM-dd")
    SET [FirstOfMonth] AS
    StrToMember("[Date].[Year Month Day].[Month].&[" + [Measures].[Month Day] +"]")
    So I need a new member to return the month day value.
    Does this make sense? Is there a better way to do this?

  • DATE FOR FIRST DAY OF THE WEEK

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

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

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

  • Report for current day and current month

    Hi gurus,
    i 've a report, where i 've to display the values for qty and cost of the material for the current day and current month
    HOw can i do this in BEx Query designer..If any document plz share
    thanks
    rakesh

    hi Kolli
    here i want to filter the data on system date,
    i wnt the report to pick the date dynamically based on the system date.
    but i think restricting on calmonth and calday is not going to solve my scenario..
    rakesh

  • ABAP for the first day of the month

    Hello BW users,
    I have a scenario which uses an ODS with cumulative key figures with Addition update type. An infocube gets data from ODS by start routine in cube's update rule. I update this ODS first then infocube. All the loads are Full and are loaded daily. This is a snapshot scenario and I load the ods on itself then load from another infocube let's say Cube1. After successful load, I update infocube on itself again then update from the same infocube, Cube1, as in ODS. Infocube load sequence is same as ODS. In the scenario ODS and infocube are wanted to be updated daily. Therefore, I have to delete the ODS's (since it is addition update type) and infocube's overlapping data in the process chain that automates the load. At this point I need two things:
    1- ABAP program that is going to give me the first day of each month.
    2- ABAP program that is going to delete the overlapping data in ODS when I load it daily. Since I can do that for infocube in process chain with standard process type of Delete overlapping requests from infocube I need it only for ODS. Because there is no standard process type to delete overlapping requests in ODS (since its update type is Addition).
    I appreciate your help. Thank you in advance.
    Sincerely,

    1- ABAP program that is going to give me the first day of each month.
    if sy-datun+6(2) = 01.
    SY-FDAYW should give you the day
    endif.
    2- ABAP program that is going to delete the overlapping data in ODS
    REPORT  <PGM NAME>.
    TABLES: RSODSACTREQ , rsseldone.
    Parameters : odsname type RSINFOCUBE default '<>ODS NAME'.
    DATA: temp_REQUEST LIKE RSODSACTREQ-REQUEST,
          temp_REQUEST1 LIKE RSODSACTREQ-REQUEST,
          temp_RNR LIKE rsseldone-RNR.
    DATA: BEGIN OF itab OCCURS 0,
          REQUEST LIKE RSODSACTREQ-REQUEST,
          TIMESTAMP LIKE RSODSACTREQ-TIMESTAMP,
          END OF itab.
    DATA: BEGIN OF itab1 OCCURS 0,
          RNR LIKE rsseldone-RNR,
          seldate LIKE rsseldone-seldate,
          seltime LIKE rsseldone-seltime,
          END OF itab1.
    SELECT REQUEST TIMESTAMP FROM RSODSACTREQ INTO TABLE itab
      WHERE ODSOBJECT = '<ODS NAME>'.
    SORT itab DESCENDING BY TIMESTAMP .
    READ TABLE itab INDEX 1.
    temp_REQUEST = itab-REQUEST.
    SELECT RNR seldate seltime FROM rsseldone INTO TABLE itab1
      WHERE source = '<Info Source Name for the ODS>'.
      SORT itab1 DESCENDING BY seldate seltime .
      READ TABLE itab1 INDEX 1.
      temp_RNR = itab1-RNR.
    *If   temp_REQUEST = temp_RNR .
    CALL FUNCTION 'RSSM_PROCESS_REQUDEL_ODSO'
      EXPORTING
        I_ODS             = odsname
        I_REQUEST         = temp_REQUEST
        I_JOBNAME         = 'i_jobname'
        I_VARIANT         =
        I_INSTANCE        =
      IMPORTING
        E_ERROR           =
        E_T_MSG           = itab1
      E_T_RNRLIST       =    ITAB1.
    *else.
    *raise exception.
    *endif.
    clear itab.
    refresh itab.
    SELECT REQUEST TIMESTAMP FROM RSODSACTREQ INTO TABLE itab
      WHERE ODSOBJECT = '<ODS NAME>'.
    SORT itab DESCENDING BY TIMESTAMP.
    READ TABLE itab INDEX 1.
    temp_REQUEST1 = itab-REQUEST.
    if temp_REQUEST = temp_REQUEST1.
    raise exception .
    endif.

  • Date picker,first day/last day of month

    Hi All
    i have two items on my page
    :p80_from_date
    :p80_last_date
    both of them are defined as date picker (dd/mm/yyyy)
    i want that the form_date will contain allways the first day of the month the the user is picking
    example suppose that the user picks in the :p80_from_date : '20/07/2009'
    then the date suppose to be '01/07/2009'
    if the user picking :p80_last_date '01/08/2009' the date suppose to be '31/08/2009' .
    i've tried to do it with computation with no success.
    i rather that after the user is picking the date he will see that the default is always the first date.
    how shall i do it ?
    thanks in advanced
    Naama

    Hello Naama,
    Now you are actually raising a new issue of date validation, which should pertains to every date field on your application.
    >> the problem is that the function is not returning Boolean
    It seems to me that you are mixing Computations and Validations. The first can set the value of an item; the second can raise an application error and include options of using a function that returns Boolean or an error text.
    The problem in your specific case is that you need to validate the date prior to using it in your Computation, however the APEX engine fires Computations before Validations. The solution might be to use a PL/SQL process with a firing point of “On Submit – Before Computations and Validations”.
    As I mentioned before, date validation should apply to all your application date items. Personally, I’m using a client side validation, fired by an onblur event, to give the user a “fair warning”. The following code matches your date format, and I’m using it in a Right-To-Left application (In the example it includes Hebrew error messages that can be changed to any text in any language you need). This function can deal with a fully formatted date string (e.g. 31/01/2010) or a string of numbers representing the date (e.g. 31012010).
    function dateValidation(pThis){
      var monthDays = [00,31,28,31,30,31,30,31,31,30,31,30,31];
      var date_len = pThis.value.length;
      if (date_len == 0){  // Date field is empty
        return true;       // or an error alert if date is mandatory
      if (date_len == 10) {
        pThis.value = pThis.value.substr(0,2)+pThis.value.substr(3,2)+pThis.value.substr(6,4);
      else {
        if (date_len != 8) {
          alert('DD/MM/YYYY התאריך חייב לכלול 8 ספרות במבנה');
          pThis.focus();
          return false;
      var DD = parseInt(trimLead0(pThis.value.substr(0,2)));
      if (DD < 1) {
        alert('מספר הימים אינו חוקי');
        pThis.focus();
        return false;
      var YYYY = parseInt(pThis.value.substr(4,4));
      if (YYYY < 1900 || YYYY > 2050){
         alert('טווח השנים המוכר 1900-2050');
         pThis.focus();
         return false;
      var MM = parseInt(trimLead0(pThis.value.substr(2,2)));
      // Checking for leap year if MM=02
      if (MM == 2) {
        var leap = (((YYYY % 4 == 0) && ( (!(YYYY % 100 == 0)) || (YYYY % 400 == 0))) ?1:0);
        if ((leap && DD > 29) || (!leap && DD > 28)) {
          alert('מספר הימים בפברואר אינו חוקי');
          pThis.focus();
          return false;
      else {
        if (DD > monthDays[MM]) {
          alert('מספר הימים בחודש זה אינו חוקי');
          pThis.focus();
          return false;
      if (DD < 10) { DD = '0'+DD; }
      if (MM < 10) { MM = '0'+MM; }
      pThis.value = DD+'/'+MM+'/'+YYYY;
      return true;
    function trimLead0(str) {
       return str.replace(/^0*/g,"");
    }Best Practice stipulates that client side validation is not enough and you should use server side validations. In your specific case, if an end user tricked the client side validation he/she deserves to receive a system error message. Still, if you want to prevent it, you need to add some PL/SQL code that validates the input date before you use it in your Computation.
    Regards,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    &diams; Author of Oracle Application Express 3.2 – The Essentials and More

  • Show data of last day of previous month against any day of current month

    Hi,
    I have fact table which contains data at date level (we have data for oct-2009 to april-2010). Our requirement is to show data of last day of previous month against any day of current month in obiee 11g. I am facing problem in Feb 2010 its picking data of 28-Jan-2010 instead of 31-jan-2010 and for April its picking data of 30-mar-2010 instead of 31-mar -2010.
    Any suggestion ???

    You're asking to filter your data set to only include rows between:
    1) last day of the previous month
    2) any day of the current month
    This can be achieved with prompting in OBIEE Answers.
    last day of previous month = TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) . The problem is you need to make query work within Oracle's Answer syntax.
    In the prompt, select the operator type for your date dimension as 'between' and default to 'SQL Results'.
    For the 'last day of previous month' , use the query:
    SELECT
    case when 1=0 then Time."Fiscal Date" else TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))
    end
    FROM ENTER_YOUR_PRESENTATION_FACT_FOLDER_HERE
    For the current date, use the query:
    SELECT
    case when 1=0 then Time."Fiscal Date" else CURRENT_DATE
    end
    FROM ENTER_YOUR_PRESENTATION_FACT_FOLDER_HERE
    Another option is to create a last_date_pervious_month variable in the RPD and have that as the default value in your prompt.

  • How to get first day of the month by the given date?

    Now, is there function in CRM system that can get the first day of the month ?
    for example:
        input date is 2007/12/12, then return 2007/12/01 (the first day of month).
    Thank you~

    Hi ping,
    data: w_date type sy-datum ,
             w_temp(2) type c.
    w_date = '20071212'.
       w_temp = w_date+6(2).
       w_temp = w_temp - 1.
       w_date = w_date - w_temp.
    write / w_date.
    Plz Reward if useful,
    Mahi.

  • Function for finding first day of the month !!

    Hi,
    I know we have function to find the last day(DD) of the month. Do we have any functions for finding the first day of the month ??? if not is there any way i can find the first date(DD) of the month .
    Bcoz i m trying to incorporate the logic for finding the first day of the month partition.
    Thank you!!!

    Shahid Ali Tcs wrote:
    There are many solution given by member in relation with your question, and all are correct .
    I want to make u know something else.
    Have you ever think why oracle has given function for last_day but no function for first.....
    I u think this question u will get the answer of your "first day finding " question.
    Because first day is alwasy 01 of every, while last day can be 30,31,29,28.....
    Got my words ........
    One more solution from my side,,,,
    SQL> select '01' || to_char(sysdate,'-MON-YY') from dual;
    '01'||TO_
    01-SEP-09Which is a completely poor way of doing it.
    Using TRUNC or LAST_DAY(..) + 1 will return a DATE datatype result.
    Your method is converting the DATE into a VARCHAR2, which then prevents further processing/date based calculations unless it is explicitly converted back to a DATE again.
    The reason Oracle hasn't provided a FIRST_DAY is because the TRUNC function already caters for it as this works with DATE's as well as NUMBER's, not because the first day is always 1.

  • How to get the date of first day of a week for a given date

    Hi gurus
    can any one say me how to get the date of first day(date of Sunday) of a week for a given date in a BW transformations. For example for 02/23/2012 in source i need to get 02/19/2012(Sunday`s date) date in the result. I can get that start date of a week using  BWSO_DATE_GET_FIRST_WEEKDAY function module. But this function module retrieves me the  start date as weeks monday(02/20/2012) date. But i need sundays(02/19/2012) date as the start date. So it would be really great if anyone sends me the solution.
    Thanks
    Rav

    Hi,
    The simplest way would be to subtract 1 from the date date which you are already getting in transformation routine, but instead of doing that subtraction manually which might need bit of errort, you can simply use another FM to subtract 1 from given date.
    RP_CALC_DATE_IN_INTERVAL
    Regards,
    Durgesh.

Maybe you are looking for

  • Updated the iTunes yesterday and now when I try to dock ipod, the com crash

    I updated the iTunes last night and now when i go to dock the new 160gb ipod...the computer says that it has detected new hardware and then crashes. I have no idea what is going on but my old 30gb ipod works just fine when I try to dock it.

  • ITunes dosen´t work

    No se qué pasa con iTunes, me sale un mensaje diciendo que falta el archivo: MSVCR80.dll  "intente reinstalar el programa para corregir este problema" Ya lo reinstalé dos veces y sigue aparaciendo el mismo mensaje. Qué debo hacer???? Translation What

  • No Master Collection available in ALL of India?

    Hello, I'm trying to buy the CS5 Master collection, having recently moved here to India to do some work. Now I was pretty surprised to see that there's no seller listed when I'm looking to buy the master collection in India. I was even more surprised

  • Airtunes not working

    The airtunes went away on my windows XP. I have an linksys wireless router WRT54G. Linksys costumer service is telling me I need set up the port forwarding and port tracking. What port number does the airpot express use?

  • Solved: Technical Communication Suite 2 Installer Crashes

    I was repeatedly getting a crash installing Tech Comm Suite 2 in Windows XP from installation files I downloaded to my hard drive. The crash happened in the preinstallation phase, right at the beginning even before a serial number was requested. The