Command to know the days until the end of the year

Although we are not on the end of the year, much less, I find this tip particularly interesting.

In a terminal let's just put this:

echo "Faltan $(($(date +%j -d"Dec 31")-$(date +%-j))) días para que termine el año $(date +%Y)."

As you can see, something like:

There are 215 days until the end of 2013.

The operation is simple, we are using the command and variable data, with date +% j we know the day of the year we areyesterday may 30 is day 150), then we get how many days the year has -d »Dec 31 ″ (... or so I understood), to finally subtract those days that the year has from the number of the current day, this will give us how many days are left.

Anyway, with the date command you can do a lot more things than I thought 😀

regards


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   eliotime3000 said

    That's good!

  2.   Leper_Ivan said

    It is also used for many other things, not just to wait for the end of the year parties .. It could be to remember the anniversary with our partner, etc.

  3.   edo said

    Those codes above, do they belong to some programming language?

    1.    103 said

      Bash

  4.   sieg84 said

    It's good

  5.   City said

    Very good, and by modifying the month and the day I can calculate other dates 🙂

  6.   cerberus said

    "Cal -j"
    o
    «Cal -j 2013»
    It shows you the day of the year. That is to say, today at this time is the 151st day of the year, although there is little left to finish ...

  7.   Leo said

    It's good to combine it with something like with notify-send:

    notify-send «DesdeLinux It's the Best :)» «There are $(($(date +%j -d»Dec 31″)-$(date +%-j))) days left until the end of the year $(date +%Y).»

    Ask just out of curiosity: can comments be formatted with a tag, such as bold or colors?

  8.   Ricardo said

    You could also use an alias to not write everything every time you want to know how many days are left:

    alias days = 'echo "Missing $ (($ (date +% j -d» Dec 31 ") - $ (date +% - j))) days until the end of the year $ (date +% Y)."'

  9.   neo61 said

    It is interesting to do it in the console, but if you do it in exel and save that file every time you open it, it will give you the data of how many days are left for whatever you want.

  10.   VulkHead said

    Very useful, thanks!

  11.   guzman6001 said

    Very useful ... Adaptable to any countdown indeed. 😛