Forum Academy Marketplace Showcase Pricing Features

Years and months since

I have a date (employee start date) and today’s date – but how do I calculate and format the time between?

Such as “Petter has worked here for: 2 years and 6 months”

I can subtract, but it asks only for “format as days/hours/etc”.

Hey @petter,

You’ll find it very common to get data sets that need to be normalized in order to work with one another. Since time in UNIX terms is noted at milliseconds since 1970, try doing your intended date operation, normalize to the UNIX timestamp and divide based on seconds matching your format.

When it comes to discovering missing features that we’d all normally expect to be present, think about it like an opportunity to get crafty with solutions. :slight_smile:

1 Like

Doing this with milliseconds is likely to be inaccurate due to leap years. So with more than a couple of years difference could be out by several days.

It will be a bit messy, but you can extract the Year and Month using :extract and then do some calculation on it.

It will need some conditions on it, so that if current month <= start month then years = current year - start year - 1 etc

1 Like

Thank you both for helping out!

Both solutions are handy actually, depending on the situation and length of calculation.

This topic was automatically closed after 70 days. New replies are no longer allowed.