(Treehouse Code Snippet) Calculating days/months/years ago

Hi @Alex_B_Centrifuge
I actually already had something very similar on my list to post to the Treehouse site from @James (as per this Slack thread: https://treepl.slack.com/messages/CC1074CQM/p1621300167000700)

However, there are things I like about both.
I like yours due to:

  • being more readable/understandable.
  • creates variable you can use for all periods (days/months/years) so you can use any/all period types regardless of the date difference.

I like Jame’s due to:

  • covers sec/min/hr/days/mths/yrs (I added ‘weeks’)
  • the separation of logic from markup

So I added some bits and combined all into one ‘super snippet’ :slight_smile:
Let me know if you can see any improvements to make / flaws to fix:

1 Like