Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: Number of day in MONTH+YEAR

  1. #1
    Join Date
    May 2006
    Posts
    167

    Default Number of day in MONTH+YEAR

    Hi,
    in a flow of data I have two fields: year and month.
    I'd like to know how many day there were in that month.
    Is there in PDI an already built-in function to retrieve that information, please?

    Thank you,
    Nicola

  2. #2
    Join Date
    May 2006
    Posts
    167

    Default

    I solved using a javascript step with:


    var num_days = return new Date(year, month, 0).getDate();


    Bye
    Nic

  3. #3
    Join Date
    Mar 2011
    Posts
    257

    Default

    I think the calculator step can do this too.
    and if it can it will be faster than a JS step.

  4. #4
    Join Date
    Nov 2008
    Posts
    777

    Default

    I tend to avoid using constructors that are deprecated...

    http://docs.oracle.com/javase/6/docs...ructor_summary

    ...so I would use the Java Calendar to solve this problem:
    Code:
    cal = java.util.Calendar.getInstance();
    cal.set(_year, _month-1, 1);                                               // Month number arg is zero-based for this method.
    var num_days = cal.getActualMaximum(java.util.Calendar.DATE);
    pdi-ce-4.4.0-stable
    Java 1.7 (64 bit)
    MySQL 5.6 (64 bit)
    Windows 7 (64 bit)

  5. #5
    Join Date
    Jun 2012
    Posts
    5,534

    Default

    One more way: Formula step, returning a Number

    Code:
    DAY(DATE([year]; [month]+1; 1) - 1)
    So long, and thanks for all the fish.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.