Skip to main content
Solved

Get number of days in month

  • August 24, 2018
  • 5 replies
  • 82 views

Forum|alt.badge.img+4

@takashi I have a dataset like this:

DateValue01/01/2018201/01/2018001/05/2018301/12/2018102/01/2018302/02/20184

I want to create an attribute for Daily Average Value in Each Month, and store the daily average (sum of values within each month ÷ number of days in that month).

The denominator is where I'm having trouble. Any suggestions on the best way to find the number of days within a given month?

Best answer by ebygomm

If you didn't want to use python, you can get the first day of the month then add a month and take away the first date to get number of days

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

hlouie
Contributor
Forum|alt.badge.img+16
  • Contributor
  • 33 replies
  • August 24, 2018

I know how to do this in Python

from calendar import monthrange
monthrange(2012, 2)

(2, 29)


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3429 replies
  • Best Answer
  • August 24, 2018

If you didn't want to use python, you can get the first day of the month then add a month and take away the first date to get number of days


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3429 replies
  • August 24, 2018

You can also use something like the following in an inline querier if your dates are in ISO format

select aa.*, strftime('%d',date(aa."date",'start of month','+1 month','-1 second')) as days_in_month from Table1 aa;

takashi
Celebrity
  • 7843 replies
  • August 24, 2018

If you didn't want to use python, you can get the first day of the month then add a month and take away the first date to get number of days

Inspired by @egomm's suggestion. Assuming that the original date/time format is %m/%d/%Y.

 

Depending on locale, the format might be %d/%m/%Y. Please specify the format explicitly, in this kind of question.

 

 


Forum|alt.badge.img+4
  • Author
  • 30 replies
  • August 29, 2018

Thanks @egomm and @takashi, I think this should work!

Since I've become such a heavy FME user, I almost always convert all dates to FME format, %Y%m%d before transforming or trying to calculate anything.