How to calculate future date

I have used the following code from http://forums.adobe.com/message/2077238#2077238.   But it does not seem to work when straddling years.
I want the use to enter a date in DateTimeField1, then the date in DateTimeField2 to add 6 months to DateTimeField1
Then DateTimeField3 to equal 4 months from DateTimeField 2.  Then DateTimeField4 to add 6 months to DateTimeField3
DateTimeField1 = user enter
DateTimeField2 = util.printd("mm/dd/yyyy", DateUtils.addMonth(new Date(Date.parse(DateTimeField1.formattedValue)),5));
DateTimeField3 = util.printd("mm/dd/yyyy", DateUtils.addMonth2(new Date(Date.parse(DateTimeField2 .formattedValue)),4));
DateTimeField4 = util.printd("mm/dd/yyyy", DateUtils.addMonth(new Date(Date.parse(DateTimeField3.formattedValue)),5));
function 
addMonth(date, months){
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();month =  ((month + months - 1) % 12) + 1;
year += parseInt(month / 12);
var days = daysInMonth(month, year);
return new Date(year, month, days);}
function
addMonth2(date, months){
var year = date.getFullYear();
var month = date.getMonth();
var day = 1;month = ((month + months - 1) % 12) + 1;
year += parseInt(month / 12);
return new Date(year, month, day);}
function daysInMonth(month, year) 
 return 32 - new Date(year, month, 32).getDate();}
When I enter 01/01/2010 in DateTimeField1, the following is that results:
DateTimeField2 = 06/30/2010
DateTimeField3 = 10/01/2010
DateTimeField4 = 03/31/2010
The desired result is:
DateTimeField2 = 06/30/2010
DateTimeField3 = 10/01/2010
DateTimeField4 = 03/31/2011

Hi,  I'm not sure I understand the result required here.  Wont 6 months on from 01/01/2010 be 01/07/2010, then 4 months be 11/01/2010 and another six months be 05/01/2011.  Your desired results have gaps of 180 days, 93 days then 181 days.
Not sure why the script isn't working for you, maybe you should try Date.parse(DateTimeField1.rawValue).  The rawValue will always be in yyyy-mm-dd format, where the formattedValue will vary depending on locale and display patterns.
Regards
Bruce

Similar Messages

  • How to calculate first date and end date of this year in Query

    Hi Expert
    I want to calculate following dates with inputted date in query.
    I have no knowledge on ABAP and I just can create a query with simple logic.
    Could you teach me how to calculate following date?
    (If inputted date is April 12 2009)
    - First date of this year (Ex January 1 2009)
    - End date  of this year (Ex December 31 2009)
    - First date of last year (Ex January 1 2008)
    - End date of last year  (Ex December 31 2008)
    - First date of this month (Ex April 1 2009)
    Thank you!
    Take

    HR_JP_MONTH_BEGIN_END_DATE   use this FM to get the begin and end date of the Date you are passing. eg when u give input as 04/12/2009, it will return
    04/01/2009 as begin date
    04/30/2009 as end date
    pass the Year in this FM HR_E_GET_FISC_YEAR_DATES, you will get the Fiscal year Begin and End Dates
    Abh

  • Calculate future dates

    Am looking for either a javascript or formcalc that will run at the client level to calculate future dates based on input into a base date.
    Example:
    Input: 30 April 2005
    Outputs:
    Next Event: Monday, 15 May 2005 (base date + 15 days)
    Next Event: Saturday, 29 June 2005 (base date + 45 days)

    I don't have such script but I have a few tips for you if you want to write a script that will do just that.
    - First, you can refer to the "input" date/time field by:
    inputDate = DateTimeField1.formattedValue;
    - You can then parse the date/month/year values
    var theYear = inputDate.substring(0,4);
    var theMonth = inputDate.substring(5,7);
    var theDay = inputDate.substring(8 );
    - Create a JS date object, useful for date manipulation.
    var dateObj = new Date();
    var baseDate = dateObj.getDate();
    var baseMonth = dateObj.getMonth();
    var baseYear = dateObj.getYear() + 1900;
    - Now you can implement a function called
    displayFutureDate(baseDate,baseMonth,baseYear,numberOfDays,outputObj)
    I leave the detailed implementation up to you. It would be a good and fun exercise.
    Good luck!

  • Calculate future date in MM/dd/yyyy format

    Hi,
    I am trying to add a 56 months to a given date (MM/dd/yyyy string) and output the date in MM/dd/yyyy format.
    Here is my code:
                   SimpleDateFormat date = new SimpleDateFormat("MM/dd/yyyy");
                   date.parse("07/30/2000");
                   GregorianCalendar gc = new GregorianCalendar();
                   gc.add(Calendar.MONTH,+56);
                   System.out.println(date.format(gc.getTime()));  I tried to assign date.parse() to a Date but there is no fomat method on Date so to add months to the date. Could someone suggest me how to calculate a future date?

    thanks for looking, just found the answer:
                   SimpleDateFormat date = new SimpleDateFormat("MM/dd/yyyy");
                   Date dt = date.parse("07/30/2000");
                   GregorianCalendar gc = new GregorianCalendar();
                   gc.setTime(dt);         //this was missing
                   gc.add(Calendar.MONTH,+56);
                   System.out.println(date.format(gc.getTime()));

  • How to calculate Deadline Date and Time

    A support desk message has been created and support team has to respond in fixed time duration.
    Creation time of message and duration of response are available.
    How to calculate the exact time and date where this deadline expires using the factory calendar.

    java.util.Date date = java.util.Calendar.getInstance().getTime(); //retrieve a date object
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(dd-MMM-yyyy);
    String s = df.format(date); //10-Aug-2001
    String t = "15042001";
    df.applyPattern("ddMMyyyy");
    d = df.parse(t);
    df.applyPattern("dd-MMM-yyyy");
    t = df.format(d); //15-Apr-2001Hey it's Friday, I'm bored

  • How to calculate start date of the week based on week number ?

    i need to get week number of the current date and based on that i need to calculate start date falling in the same week for last year.
    Eg. today is 31st week of year and 31st july date. so what will be the date on the 31st week of last year. i need the start date of that week.
    we can calculate the week number by select to_char(sysdate,'ww') from dual.
    DO we have a single line query for that or will it require writing a pl/sql block ?

    you can try following query
    it can be as inline but for more clean look and create it as select with include select
    with t as
    (select sysdate as dt from dual)
    select to_char(prev_year_dt - to_char(prev_year_dt, 'D') + 1, 'DD.MM.YYYY') as start_of_week from (select
    -- get day from prev year with the same week number
        case
               when to_number(to_char(add_months(dt, -12), 'WW')) > to_number(to_char(dt, 'WW')) then
                dt - (to_number(to_char(add_months(dt, -12), 'WW')) - to_number(to_char(dt, 'WW'))) * 7
               when to_number(to_char(add_months(dt, -12), 'WW')) < to_number(to_char(dt, 'WW')) then
                dt + (to_number(to_char(dt, 'WW')) - to_number(to_char(add_months(dt, -12), 'WW'))) * 7
               else
                add_months(dt, -12)
           end as prev_year_dt
      from t) t1good luck
    Sergii
    'Monday' is not first day of week in 100% ;)
    Edited by: Galbarad on Jul 30, 2012 11:00 PM

  • How to calculate retirement date

    Dear Guru.
    i want to calculate the retirement date.
    input for calculating retirement date is employee DOB.
    from employee date of birth we need to add 58 years.
    any standard function module is there for calculating retirement date.
    please help me .

    Hello Shail,
    You have to write the Dynamic Action in IT0002. So that when IT0002 is maintained, Dynamic action is triggered and IT0041 is created.
    1) Let's say, there is a Date Type created for Retirement;  Date Type = R1
    2) to calculate the date you have to do following;
    FC      N0
    S
    Variable Function Part
    =======================================
    06
    01
    W
    P0041-BEGDA=PSPAR-BEGDA
    06
    02
    W
    P0041-ENDDA='99991231'
    06
    03
    W
    P0041-DAR09='R1'
    06
    04
    F
    Get_Retirement_Date(ZHR_DYNROUTINE)
    06
    05
    W
    P0041-DAT09=RP50D-DATE1
    3) Include "ZHR_DYNROUTINE" need to be created. Within this include a subroutine "Form Get_Retirement_Date.....Endform" need to be created.
    4) Inside "Form Get_Retirement_Date.....Endform", you can write your code of the function module to calculate the Retirement date and then pass it in structure RP50D-DATE1;
    RP50D-DATE1 = Retirement Date calculated from function
    There is another option. You can also develop user exit ZXPADU02. If your hiring action infogroup has IT0041 included, then you can also do this calculation inside the user exit and populate it in IT0041 with correct date type.

  • How to calculate a date in the future and set it as field value?

    I'm trying to set the value of a read-only field to a date and time 72 hours from the current date and time. Here's how I'm doing it now:
    var futureInMilliseconds = new Date().getTime() + 259200000; // current date and time + 72 hours in milliseconds
    field.value = new Date(futureInMilliseconds);
    The field is formatted as "m/d/yyyy h:MM tt". When I test this in the debugger I see it listing the correct date and time in the future, but the value applied to the field is always the current date and time. So, I'm having a difficult time getting this to work for something that should be fairly straight forward and simple. I'd appreciate any suggestions.

    What is the "field" object?
    What happen when you use "event" for the object and not "field"?
    Even if this script is placed at the document level or any other location, it is still a calculation. It just not a field Custom Calculation Script. You are adding one value to another to get a new value.

  • How to calculate delivery date

    Hello,
    I'm trying to use a formatted search in a Sales Order to calculate the delivery date per row.
    I found the following that could be my answer, but not sure how to proceed:
    DATEADD (datepart, number, date)
    Based on the item information on tab 'Planning' field Lead Time (OITM.LeadTime) I want to calculate the document date plus the Lead Time (or should I create a UDF?).
    I did created the following query:
    DATEADD(day, $[OITM.LeadTime], $[$10.0.DATE])
    When running the query I get the following:
    DATEADD(day, N'', CONVERT(DATETIME, '20080325', 112))
    As you can see it didn't fill the 'number' with the leadtime information (which is 3 in my case).
    And I receive the following error:
    1). [Microsoft][SQL Native Client][SQL Server] Incorrect syntax near 'day'. 2).[Microsoft][SQL Native Client][SQL Server] Statement 'User-Defined Values'(CSHS) (s) could not be prepared.
    How can I my result?
    Regards,
    Petronella

    This seems to work.
    SELECT DATEADD(day, (SELECT LeadTime FROM OITM WHERE ItemCode = $[$38.1.0]), $[$10.0.DATE])
    Regards,
    Douglas

  • How to calculate the data in bex

    Dear all,
                i have a service order no and it current active status  and it time stamp details in my query
    example
    sevice orer no  posting date name    current active status  active status date    part aging
    800000243      15.01.2009   shahina part despatched          A     17.01.2007  
    in my ods i have
    sevice orer no  posting date name    current active status  active status date    part aging
    800000243      15.01.2009   shahina part despatched          A    17.01.2007  
    800000243      15.01.2009   shahina part pending               x    16.01.2007  
    800000243      15.01.2009   shahina part for asp                 x    17.01.2007  
    i want to calulate the aging of part pending to part despatched
    17.01.2009   -   15-01.2009   = 2 days
    i want to display in my bex like this
    sevice orer no  posting date name    current active status  active status date    part aging
    800000243      15.01.2009   shahina part despatched          A     17.01.2007      2
    ( in bex report i want to display only active status )
    can any one help me please to solve this issue
    Regards
    shahina

    Hi vamsi talluri ,
      i working in crm reports ( service ) here i want to calulate the differance between the old status that is inactive status date to part despathed date
    sevice orer no  posting date name    current active status  active status date    part aging
    800000243      15.01.2009   shahina part despatched          A     17.01.2007  
    in my ods i have
    sevice orer no  posting date name    current active status  active status date    part aging
    800000243      15.01.2009   shahina part despatched          A    17.01.2007  
    800000243      15.01.2009   shahina part pending               x    16.01.2007  
    800000243      15.01.2009   shahina part for asp                 x    13.01.2007  
    i want to calulate the aging of part pending to part despatched
    17.01.2009   -   13-01.2009   = 4 days
    i want to display in my bex like this
    sevice orer no  posting date name    current active status  active status date    part aging
    800000243      15.01.2009   shahina part despatched          A     17.01.2007      4
    in bex i am dispaying only active satus but i want calculate diff bet active status which i am dispalying in the bex analyzer and old status whaer the data are available in sercice order ods
    please help me how to perform the calculation
    Regards,
    shahina..!
    ( in bex report i want to display only active status )
    can any one help me please to solve this issue
    Regards
    shahina..!
    Edited by: Shahina A on Jan 21, 2009 6:13 AM

  • How to calculate start date and last date for current week

    Dear All.
    i want to calculate the start of the current week as well as the last date of the current week, our week start from Saturday and ends of Friday i.e. Saturday is the first day of the week and Friday is the last day of the week.
    How can i acheive this in universe Designer?.
    Please help...

    Hi
    the formulas in webi will be as follows
    for startdate
    =RelativeDate(LastDayOfWeek(CurrentDate());-8)
    for enddate:
    =RelativeDate(LastDayOfWeek(CurrentDate());-2)
    Regards,
    Ranganath

  • How we calculate the date difference between two list in SharePoint 2010

    Hi friend's....I have two list first is list1. In this list i have two coulmn start_date and End_date. In second list2 i have two column HolidayName and Holiday_date. Now i want two find the number of day in list1 Excluding Weekend and Holiday_date(that
    column from list2). How i will do ..? Please help me dosto..

    Thanks for reply...
    I have done the date difference in list1. But i want to Exclude the Holiday_date form list2.
    I have list1 - Start_date , End_date, Number_of_day(Exclude weekend and Holiday_date between Start_date and End_date )
    list2 - HolidayName, Holiday_date
    Now how i will calculate the Number_of_day in first list.

  • FM to calculate future date

    Hi,
    Im looking for a function module to add number of days ( working days only ) to a given date and return me the resultant date.
    For example, input date 25.02.2009. I need to add 5 working days and the resultant date will be 04.03.2009.
    Thanks for the help

    Hi,
    The FMs of your interest would be:
    DATE_IN_FUTURE - Calculates a future or past date
    WDKAL_DATE_ADD_FKDAYS - Number of working days in a date range
    HOLIDAY_GET - All holidays in a factory calendar
    DATE_CHECK_WORKINGDAY - Determines if a single date is a working day
    There are no direct FM as far as i know. You can use the above FMs and write logic accordingly to get your desired result. Do search on the above FMs for their details.
    Cheers.

  • How to Calculate End-Date for a given Startdate in business hours without holidays

    Hello Experts,
    I need to create a plsql function where we need to determine end date for a task. For this, input will be only start date & number of hours allocated for that task. Based on this input we need to exclude Business hours & need to include only Business hours. and in the end we need to achieve the end date after the hour addition to the start date.
    Example : INPUT: 03-OCT-2013 12:00:00 PM /
                                  Hours Allocated 30 Hrs.
    Business Hours - 11 AM to 9 PM.
    So time starts from or Startdate is Friday 03-OCT-2013 12:00:00 PM. 
    So If I want to calculate the end-date by adding 30 hours to it, it should come WednesDay 09-OCT-2013 12:00:00 PM because I excluded Weekends & considered only business hours that is 11 am to 9 pm.
    I am not able to get any such guidance in Internet as most of the docs are having start & end date as input.
    Please help!
    Thanks in advance !!

    Hi,
    As Christ said, there's no nuilt-in Oracle function to tell whether a given DATE is a holiday or not, partially because there's so much local variation in holidays.  You can write a function like that (see http://forums.oracle.com/forums/message.jspa?messageID=3351081 ), but creating a table will be simpler and more efficient.
    I suggest creating a row for every date, whether it's a work day or not; that way, you can have variations in the schedule (e.g., schedule changes and
    partial holidays).
    CREATE TABLE  work_calendar
    (   dt  DATE       PRIMARY KEY
                       CONSTRAINT  work_calendar_dt
                           CHECK (dt = TRUNC (dt))
    ,   day_type       VARCHAR2 (8)  NOT NULL
                       CONSTRAINT  work_calendar_day_type
                           CHECK ( day_type IN ( 'HOLIDAY'
                                               , 'WEEKEND'
                                               , 'WORK DAY'
    ,   start_time     DATE
    ,   end_time       DATE
    ,   work_hours     NUMBER
    ,   work_hours_since_1970     -- or some point earlier than you'll ever need
                       NUMBER
    ,   CONSTRAINT  work_calendar_start_time
            CHECK ( TRUNC (start_time) = dt)
    ,   CONSTRAINT  work_calendar_end_time
            CHECK ( TRUNC (end_time) = dt)
    This will let you do a lot of the calculations you need without a function.

  • How to calculate first date of month from a given date in IDT BusinessObjects

    Hello Experts,
    I have a date field in IDT Universe which shows date in this format: Dec 13,2014 12.00.00 PM. Now I want to extract first day and last day of month from this date value. For example: here I want to see Dec 01,2014 12:00:00 PM and Dec 31, 2014 12:00:00 PM in First day of month and Last day of month columns. Also, if database date value is Nov 17, 2014 12:00:00 PM then in first day of month column, it should show Nov 01, 2014 12:00:00 PM and in last day of month it should show Nov 30, 2014 12:00:00 PM.
    I got some google help but 'Date' function is not supported by IDT tool in BusinessObjects.
    Please help.
    Thanks in advance.

    Hi
    Try to use the DB Functions to find out the First and last day. Please find out the below screenshot.
    If DB is BW, you can calculate the First and last day @ BW level use same object in BO directly.
    SQL DB:
    http://docs.oracle.com/html/A95915_01/sqfunc.htm#i1006893
    Oracle DB:
    http://msdn.microsoft.com/en-US/library/ms189794(v=sql.90).aspx

Maybe you are looking for

  • HP Photosmart 7520 e-All-in-O​ne Printer

    I am using Win 7 32 bit OS and have this printer on my network wireless hookup! I can print from all devices, but My computers can not detect the card reader! The reader works, because I can print pictures from the memory card while it is in the read

  • Should I let Windows 8.1 Update Nvidia Video Drivers?

    Loading Windows 8.1 to a secondary hard drive in my Early-2009 Mac Pro via Boot Camp was a frustrating exercise. But after four tries it took when I found out that there were problems with the Nvidia graphics board driver. During the final successful

  • Drill down for notes

    Post Author: jhopewell CA Forum: Xcelsius and Live Office I am trying to figure out if there is a way to enable a drilldown that will allow people to see notes related to an individual item within a chart.  i.e. a bar chart where you could click on a

  • CS4 very slow under Win7 Ultimate 64 ...?!

    Hi, i bought a new PC with Intel i7-950, 12 GB Corsair DDR3 RAM and ASUS Radeon 4890 Graphiccard, OS is Windows 7 Ultimate 64 for a faster Work (so the Idea), but now i draw my first Picture with my Wacom Intuos 2 on CS4 64 Bit and its horrible slow

  • Help with CF9 Standard Install and Mac OS Server (Snow Leopard Server)

    Hello, I recently purchased a mac mini server (with snow leopard server) and will be using it to host my CF9 applications.  This install is WAY different than the install needed on a windows machine.  I tried to install it once and somehow hosed up A