Skip to content
Advertisement

Days between dates into minimum non-date measurement

I have a column that represents the number of days from an event until today.

JavaScript

I am trying to figure out a way to represent this as a string such that it shows the rounded number of days / weeks / months / years. However, I would like it to choose “D”/”W”/”M”/”Y” based on the minimum value of each that is > 1. Some rounding is fine to make sure that a few days off doesnt mess it all up.

For example, if the input number is 31, I don’t want “4Weeks”, but instead “1Month”.

Using the example values about, I would expect:

JavaScript

Advertisement

Answer

I did it without the round, it’s much easier that way:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement