Solved

Get number of days in month

  • 24 August 2018
  • 5 replies
  • 8 views

Badge

@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?

icon

Best answer by ebygomm 24 August 2018, 20:36

View original

5 replies

Badge +11

I know how to do this in Python

from calendar import monthrange
monthrange(2012, 2)

(2, 29)

Userlevel 1
Badge +10

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

Userlevel 1
Badge +10

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;
Userlevel 2
Badge +17

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.

 

 

Badge

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.

Reply