bildwelt
E2E FORUM
E2E Bridge E2E Commerce

Determining number of days in month for date difference

E2E Forum Modeling & Development Determining number of days in month for date difference

This topic contains 2 replies, has 3 voices, and was last updated by  Alfred 2 years, 9 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1825

    angelolavides
    Participant

    Hi,
    I would just like to inquire how we can derive the number of days from the month duration type?

    I was trying the date difference function and the result is the same for February and March even though March has more days.

    If my input is February 1 to March 1 the output is 1 month
    If my input is March 1 to April 1 the output is also 1 month

    Many thanks for your suggestions.
    – Gelo

    #1826

    Andi
    Moderator

    Hi Gelo,
    in deed, date difference function does not return days for durations longer than 1 month. It is not very customizable.

    You can achieve this by converting the dates in time ticks and calculating those values. Here the script to get number of days between 2 given dates:

    local dif = date1.convertDateTimeToTimeTicks() - date2.convertDateTimeToTimeTicks();
    set durationInDays = convertToFloat(dif / 86400);

    86400 is the number of seconds of one day. With a different divisor, for instance 3600, you can calculate the difference in hours.

    #1827

    Alfred
    Moderator

    Another solution is to use the %j of printDateTimeExpression() which returns the day of the year as decimal number [001,366].

    local fromDate = convertToDateTime("2014-02-01");
    local toDate = convertToDateTime("2014-03-01");
    local fromDateDayOfTheYear = fromDate.printDateTimeExpression("%j");
    local fromDateDayOfTheYearNumber = fromDateDayOfTheYear.parseIntegerExpression("009");
    local toDateDayOfTheYear = toDate.printDateTimeExpression("%j");
    local toDateDayOfTheYearNumber = toDateDayOfTheYear.parseIntegerExpression("009");
    local daysOfMonth = toDateDayOfTheYearNumber - fromDateDayOfTheYearNumber;
    

    In the example above daysOfMonth is 28.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.