How to add days to a DATE variable?

Hi,
I want to run a query based on my date variable with subtracting 7 days from it. Thanks.
p_date DATE;
Select * from table where theDate between to_date(p_date , 'yyyy/mm/dd') to_date(p_date - 7, 'YYYY/mm/dd');
Thanks.

If p_date is a DATE data type variable why are you using TO_DATE? It is, by definition, already a date.
WHERE theDate BETWEEN (p_date-7) AND p_date;

Similar Messages

  • How To Add Days into a Date from java.util.Date class

    I have a problem when i wants to add 2 or days into a
    date object geting by java.util.Date class. so please help me resolve this issue?
    for e.g i have a date object having 30/06/2001,
    by adding 2 days i want 02/07/2001 date object ?
    Code
    public class test2
    public static void main(String args[])
    java.util.Date postDate = new java.util.Date();
    myNewDate = postDate /* ?*/;
    Here i want to add 2 date into postDate

    Use Calendar...
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DAY, 2); // I'm not sure about that "DAY"

  • Jquery how to add days to a date and display in a sharepoint field

    hi
    I have a column 'Date' , where user will select the date . Another column Grace Period where user enters number. I have a column 'Due Date' = Date + Grace Period
    I cannot use out of the box calculated column as it is not displayed in the newform.aspx.
    Is there any way to achieve it
    Thanks

    To get & set value via jquery, you first need to download jquery and save query in your site. Later add jquery ref to your script then get the column value. Refer below thread:
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/a9fb3163-109c-4309-96d2-4f2f19e6824a/sharepoint-and-jquerygetting-setting-sharepoint-form-fields?forum=sharepointgeneralprevious
    http://stackoverflow.com/questions/8559559/javascript-to-get-sharepoint-form-field-value-to-a-variable
    Since you are new so i would suggest you that first try with simple query on page then build the advance.
    http://sympmarc.com/2011/05/03/adding-jquery-to-a-sharepoint-page-step-one-always/
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • How to add days to a date?

    Dear all
    I work with jdeveloper 11.1.4
    I have created my BC.
    I have 3 attribute on Vacation entity.
    startDate
    numberOfDays
    endDate
    I want to set the endDate value to be startDate+numberOfaDays
    Can any one helps me.

    You can achieve the same by writing a small piece of code in EntityImpl class or backing bean,depends on the use case.
    if (VO.getCurrentRow().getAttribute("startDate") != null){
    Calendar cal = Calendar.getInstance();
    cal.setTime(convertDomainDateToUtilDate((oracle.jbo.domain.Date)VO.getCurrentRow().getAttribute("startDate")));
    cal.add( Calendar.DATE, numberOfDays);
    oracle.jbo.domain.Date domDate = convertUtilDateToDomainDate(cal.getTime());
    VO.getCurrentRow().setAttribute("endDate",domDate );
    In the above code the utility method "convertDomainDateToUtilDate" just converts the jbo.domain.Date to java.util.Date and "convertUtilDateToDomainDate" method does the reverse.
    The code above holds good for backing bean but if You need to implement the same in EntityImpl then you just have to tinker around the code to get the proper entity attribute and set them properly.
    Hope this helps.
    -Sanjeeb

  • How to add days to a date value in SQL plus

    I would like to perform what ADD_MONTHS does, but for days.
    I have tried ADD_DAYS with no result. It sais it doesnt recognise the column.

    Subtracting two dates gives the number of days beteen them. So, adding or subtracting a number and a date will increment or decrementthe date by that number of days.
    If you really want a function, then:
    CREATE FUNCTION add_days (p_date IN DATE,
                              p_days IN NUMBER) RETURN DATE AS
    l_ret_dt DATE;
    BEGIN
       RETURN (p_date + p_days);
    END;and you would cal it like:
    SQL> SELECT sysdate, add_days(sysdate, 5) FROM dual;
    SYSDATE     ADD_DAYS(SY
    29-NOV-2005 04-DEC-2005However, a function is certainly overkill for something that can be done simply as:
    SQL> SELECT sysdate, sysdate + 5 FROM dual;
    SYSDATE     SYSDATE+5
    29-NOV-2005 04-DEC-2005TTFN
    John

  • How can I add days to a date?

    I need to find a way to add days to a date. For example, today is 10/3/03 and I want to add 180 days to that. How do I do that? Here is my code so far....
    import java.util.*;
    import java.text.*;
    public class Loan
         String date;
         String loanEndDate;
         public void setDate()
    GregorianCalendar gregNow = new GregorianCalendar();
    Date now = gregNow.getTime();
    DateFormat shortDate = DateFormat.getDateInstance(DateFormat.SHORT);
    date = shortDate.format(now);
    public String getDate()
    return date;
    public void printLoanBegDate()
              System.out.println("Loan Beg Date: " + date);
         public String setLoanEndDate()
              loanEndDate = (getDate() + 180);
              return loanEndDate;
         public void printLoanEndDate()
              System.out.println("Loan End Date: " + loanEndDate);
    The output is displayed by the following program:
    public class DemoLoan
         public static void main(String[] args) throws Exception
         Loan anLoan = new Loan();
         anLoan.setDate();
         anLoan.printLoanBegDate();
         anLoan.setLoanEndDate();
         anLoan.printLoanEndDate();
    The output is as follows:
    10/4/03
    10/4/03180 - - Why does this print the 180 afterwards? How can I get that to display the date 180 days into the future??
    Thanks

    Re: storing your dates as Dates, I mean don't have a field in your class called "date" which is a String. Have a field in your class called "date" which is a Date. If one aspect of your class is a moment in time, then use the java class that best represents a moment in time: java.util.Date. Don't make things more complicated than they have to be.
    Re: adding, it's in the docs:
    http://java.sun.com/j2se/1.4.1/docs/api/java/util/Calendar.html
    and
    http://java.sun.com/j2se/1.4.1/docs/api/java/util/GregorianCalendar.html
    But anyway it's like:
    Calendar c = new GregorianCalendar(); // now
    c.add(Calendar.DATE, 180); // 180 days from now
    Date nowPlus180 = c.getTime();
    DateFormat shortDate = DateFormat.getDateInstance(DateFormat.SHORT);
    System.out.println(shortDate.format(nowPlus180));

  • How i can add days to a date using sql

    Hi.
    Sorry the question, it's a very simple question, but i'm not finding the answer to that.
    I need some function that act just like the function add_months, but instead adding months, it need to add days to a date.
    I've used the function add_days once, but now, my select returns an error code when i try to use that function.
    My Oracle version is Oracle8 8.0.5.0.0
    runnig under Linux.
    Thanks,
    Klaus Paul

    To add days just do date arthmetic. Ex
    SQL> select sysdate+10 from dual;
    SYSDATE+1
    05-MAR-00
    add_days is a not Oracle date function.
    null

  • Require a function module to add days to a date?

    My purpose is to add days to a particular date and get the resulting date. I tried using this function module "RP_CALC_DATE_IN_INTERVAL", but the problem is this function module only accepts two digits for days. i.e. i am only able to add a maximum of 99 days to a particular date, but i do want to go further and add more so please tell me if there is any function module which shall help me add 3 digit days to a date.

    Hi Kiran,
    You can directly add days to the date.
    Eg:
    DATA date LIKE sy-datum.
    DATA days TYPE i.
    date = sy-datum.
    days = 100.
    date = date + days.
    WRITE date.
    Regards
    Wenceslaus

  • How to get days between two dates

    Hi ,
    How to get days between two dates.
    Regards,
    Ramesh.

    Hi Ramesh,
    REPORT ZDATEDIFF.
    DATA: EDAYS   LIKE VTBBEWE-ATAGE,
          EMONTHS LIKE VTBBEWE-ATAGE,
          EYEARS  LIKE VTBBEWE-ATAGE.
    PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
                TODATE   LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
      exporting
        i_date_from          = FROMDATE
        i_date_to            = TODATE
      I_FLG_SEPARATE       = ' '
      IMPORTING
        E_DAYS               = EDAYS
        E_MONTHS             = EMONTHS
        E_YEARS              = EYEARS.
    WRITE:/ 'Difference in Days   ', EDAYS.
    WRITE:/ 'Difference in Months ', EMONTHS.
    WRITE:/ 'Difference in Years  ', EYEARS.
    INITIALIZATION.
    FROMDATE = SY-DATUM - 60.

  • How to calculate days between two DATES

    How to calculate days between two DATES ?
    which is the functional module for that ?
    help me

    Hi,
    use function module : it works,
    HR_HK_DIFF_BT_2_DATES
    give output format = 03 and get the value in days.
    code is as below :
    data : DATE1 type P0001-BEGDA,
    DATE2 type P0001-BEGDA,
    YEARS type P0347-SCRYY,
    MONTHS type P0347-SCRMM,
    DAYS type P0347-SCRDD.
    date1 = '20070331'.
    date2 = '20070101'.
    CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
    EXPORTING
    DATE1 = date1
    DATE2 = date2
    OUTPUT_FORMAT = '03'
    IMPORTING
    YEARS = years
    MONTHS = months
    DAYS = days
    EXCEPTIONS
    INVALID_DATES_SPECIFIED = 1
    OTHERS = 2
    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 : days.
    Reward points, if helpful,
    Regards,
    Sandeep Kaushik

  • How do I add days to a date in Numbers?

    I want to build a chart that will add 151 days to a date. In Numbers 08 I used (date entered + 151) and it worked. How is it done with Numbers 09? I get an error that I can not compare dates and numbers

    e3farms,
    As far as I can see, with respect to your problem Numbers '09 works the same way as its predecessor. In the example below 100 is added to Jan 20, 2009, yielding the same result in each case.
    pw

  • Add days to a date - BI Publisher

    Hello,
    I am trying to add 7 days to a date. The date starts as DD-MM-YY format, but I need it to display as DD.MM.YYYY.
    I can get the following to return the date in the correct format:
    <?xdofx: to_date(to_char('20'||substr(DUN_DATE,7,2)||'-'||substr(DUN_DATE,4,2)||'-'||substr(DUN_DATE,1,2)),'DD.MM.YYYY')?>
    But I am unable to add 7 days to this date. I have tried using +7 in various places in the tag but no luck. Here are some things I've tried:
    Within the "to_char" function causes error "oracle.xdo.parser.v2.XPathException: Cannot convert 2010-11-30 to number"
    <?xdofx: to_date(to_char('20'||substr(DUN_DATE,7,2)||'-'||substr(DUN_DATE,4,2)||'-'||substr(DUN_DATE,1,2)+7),'DD.MM.YYYY')?>
    Within the "to_date" function causes the same error "oracle.xdo.parser.v2.XPathException: Cannot convert 2010-11-30 to number."
    <?xdofx: to_date(to_char('20'||substr(DUN_DATE,7,2)||'-'||substr(DUN_DATE,4,2)||'-'||substr(DUN_DATE,1,2))+7,'DD.MM.YYYY')?>
    Outside all functions itstill errors, but with a slightly different error: "Cannot convert 30.11.2010 to number"
    <?xdofx: to_date(to_char('20'||substr(DUN_DATE,7,2)||'-'||substr(DUN_DATE,4,2)||'-'||substr(DUN_DATE,1,2)),'DD.MM.YYYY')+7?>
    Any ideas how to get the calculation to work correctly?
    Thanks in advance,
    JJ

    Found a soution, it's not very clean and there are probably better ways, but it works.. if anyone has alternatives I'd be intereseted.
    1.) Set a variable XDUN that converts the date from DD-MM-YY to the the BI-supported date format YYYY-MM-DD using substring and concat functions:
    <?xdoxslt:set_variable($_XDOCTX, ’XDUN’, concat('20',substring(/ARDLP/LIST_G_CORRESPONDENCES/G_CORRESPONDENCES/DUN_DATE,7,2),'-',substring(/ARDLP/LIST_G_CORRESPONDENCES/G_CORRESPONDENCES/DUN_DATE,4,2),'-',substring(/ARDLP/LIST_G_CORRESPONDENCES/G_CORRESPONDENCES/DUN_DATE,1,2)))?>
    2.) Set another variable XDUN7 based on the first variable, and add 7 days there. Also formats the date in DD.MM.YYYY format:
    <?xdoxslt:set_variable($_XDOCTX, ’XDUN7’,xdoxslt:ora_format_date(xdoxslt:ora_format_date_offset(xdoxslt:ora_format_date(xdoxslt:get_variable($_XDOCTX,’XDUN'), 'YYYY-MM-DD'),7,'+'),'DD.MM.YYYY'))?>
    3.) Call the variable to display the date + 7
    <?xdoxslt:get_variable($_XDOCTX, ’XDUN7')?>
    Thanks,
    JJ

  • To extract a day from a Date variable

    Hi
    I have a date variable and i want to get the day into a PL/SQL variable.Can you tell me how to do that .
    eg I have 12/30/2002 (MMDDYYY)
    and i want 30 in another variable ..
    Thanks in a advance

    SQL> declare
      2  ln number;
      3  begin
      4  ln := to_char(sysdate, 'DD');
      5  dbms_output.put_line(ln);
      6  end;
      7  /
    22
    PL/SQL procedure successfully completed.
    SQL>
    [pre]
    Piece of cake.  No, thanks, I've just had breakfast.
    APC                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Add Days to a Date field

    Hi all,
    I have the following requirement:
    I have a date field 0calday and the user would like to add a specific no.of days to it, like for example 10 or 15 days. Then we use this computed date field in calculations in the query. Could you please help and let me know how we can no.of days to a date field? And also how we can compute no.of days between two date fields?
    Regards,
    Ashmith Roy

    Hi Ashmith,
        When the user enters both date and no. of days, and if you want to calculate no of days from the user entered date I think you can go for an exit where you can use the available function module which calculates the no of days from starting of the month for the given date. Then you can add up the days entered by the user and use another available function module which converts it to the dat format again based on the given days and the old date. I don't remember the function module names but i am sur ethey are available.
    If the above thing is made possible then I think getting no of days between two dates is not a problem. Well i hope this will help you.

  • Add days to a date field on adobe form

    Hi,
    I have to add 15 days to a date field how i do that on javascript or formcalc?
    Thank you in advance.
    Miguel

    Hi,
    The below is in js code.
    I had a caluclated date time field on the screen which displayed the current date.
    The below code will just add 15 days to the day part of the date.
    for moving it to month if its more than 31 is to be handled by you.
      var valArray = this.rawValue.split("/");
      var newDate = valArray[1] + 15;
      var actualVal = Date.parse(newDate+"/"+valArray[0]+"/"+valArray[2]);  
    var dateType=new Date(actualVal);
    this.rawValue = dateType;
    Hope this helps you out, let me know if you need any more info.
    Cheers,
    Sai

Maybe you are looking for