Day counter with JavaScript

Walter Nascimento
Walter Nascimento | EN
1 min readSep 3, 2020

Simple day counter using HTML and JS

[clique aqui para ler português]

Have you ever needed to know the difference in days between an end date and a start date? If so then we will create something simple to facilitate this counting of dates.

CODE

First we will create the interface, we will do something simple, using only HTML.

HTML code

In the HTML structure, two inputs were created, one to receive the start date and the other with the end date.

Now let’s create the countDays() function.

JS code — Function countDays

In this function (countDays()), the value of the start date and the end date is retrieved, and in the diff variable, the dates are subtracted and converted into a timestamp, after which a small calculation of the difference is made with the total of days.

ready as simple as that.

Demo

See the complete project working below.

Project on codepen

Youtube

If you prefer to watch, I see the development on youtube (video in PT-BR).

Video on youtube

Thanks for reading!

If you have any questions, complaints or tips, you can leave them here in the comments. I will be happy to answer!

😊😊 See you! 😊😊

--

--