# Counting time from and to

Friends, do you need your advice (maybe someone faced such a problem)?

You have to count working hours. The user enters the start of the job and the end of the job, and the program outputs the amount of time spent on the job.

I can’t figure out how to calculate the logic correctly Yes, if a person worked for more than an hour, then we subtract the start time from the end time of work - we get the number of hours.
What to do with minutes? If a person started working, for example, at 13.30, and finished working at 14.10, then:

1. We count the hours: 14-13 = 1
2. We count the minutes: 10 - 30 = -20, which is clearly not correct.

Question: how to get out of this situation?

Convert the start time to seconds since 1970, convert the end time to seconds since 1970, subtract one from the other, and then convert the answer into hours and minutes.

You may need JavaScript to accomplish all of that.

Hm…interesting…forgive my impudence - maybe you have an example?

I don’t have an example but if you Google calculate time between two times javascript you can find some instructions. It’s probably also possible to use a Google Sheet formula to calculate this.

Understood thanks I looked in the direction of Google Spreadsheets, but there is an option to calculate time immediately as a mathematical operation - but this doesn’t suit me, because I don’t work with Google Spreadsheets in this case.

Friends, my head is boiling So, we have a date and time input.
We also have a block “Seconds since 1970”.
Tell me how to get the number of seconds from 1970 from the date and time entered by the user?

Thank you!