# Thread: Number of day in MONTH+YEAR

1. Senior Member
Join Date
May 2006
Posts
167

## 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. Senior Member
Join Date
May 2006
Posts
167
I solved using a javascript step with:

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

Bye
Nic

3. Senior Member
Join Date
Mar 2011
Posts
257
I think the calculator step can do this too.
and if it can it will be faster than a JS step.

4. Senior Member
Join Date
Nov 2008
Posts
777
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);```

5. Senior Member
Join Date
Jun 2012
Posts
5,534
One more way: Formula step, returning a Number

Code:
`DAY(DATE([year]; [month]+1; 1) - 1)`

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•