Custom expression to calculate number of days in a given month.

Custom expression to calculate number of days in a given month.

book

Article ID: KB0079376

calendar_today

Updated On:

Products Versions
Spotfire Analyst All Versions

Description

If there is a requirement to calculate the number of days in a given month, the following expression will provide this and it does not depend on local client regional settings.

Issue/Introduction

Custom expression to calculate number of days in a given month.

Resolution

Here is an example custom expression to calculate the number of days in a month:

DateDiff("day",
    DateAdd("day",(-DayOfMonth([MyDateColumn])) + 1,Date([MyDateColumn])),
    DateAdd("month",1,DateAdd("day",(-DayOfMonth([MyDateColumn])) + 1,Date([MyDateColumn])))
)

where [MyDateColumn] is your column with a DataType of Date or DateTime for which you want to calculate how many days are in that month.

Additionally, this expression used included in the above expression is useful for finding the first day of a given month:

DateAdd("day",(-DayOfMonth([MyDateColumn])) + 1,Date([MyDateColumn]))
 


 

Additional Information

Doc: TIBCO Spotfire Professional User's Guide > Date and Time Functions