calculate the difference in seconds between two date & t

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear Friends,
I want to calculate the difference in seconds between two date and time. As for example I have two dates and times like
2012.09.28 at 13:30:00
2017.11.25 at 16:32:55
Now I want to know how much seconds are there between these two data and time. I use C as programming language.

I also want to say that I use AVR uC and as compiler I use mikroC PRO for AVR. In mikroC there is built in library to do the job. But I do not want to use it. I want to build my own algorithm.

Please help me.

Kind regards
Hasan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use the mktime function from to calculate the number of seconds since the epoch for each date. After that just substract the values.

Daniel Campora http://www.wipy.io

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

danicampora wrote:
Use the mktime function from to calculate the number of seconds since the epoch for each date. After that just substract the values.

is it in ATMEL STUDIO?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you program avr32 then yes, if you program avr8 then no.

It's really the source of mktime() you'd want to get access to. The source of the C library should be available somewhere as I assume it's published under an open license.

Failing that there have been a number of threads in AVR Forum discussing time.h and the functions it provides access to. Maybe search those out?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
as compiler I use mikroC PRO for AVR
Then why are you posting in the AVR Studio forum (AVRStudio uses the avr-gcc compiler)? And since you want to write your own, then the compiler you are using is irrelevant.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Failing that there have been a number of threads in AVR Forum discussing time.h and the functions it provides access to. Maybe search those out?

Hmmm--I think I posted my "make Unix-style timestamp form BCD date/time from RTC" recently. And there were other suggestions in the same thread. Searching...
https://www.avrfreaks.net/index.p...
https://www.avrfreaks.net/index.p...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

difference between any two dates/times is a quite complex algorithm. Not prudent to DIY.

If the date range is limited to say, this century, it's not so bad; just leap years and leap seconds to deal with.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear
Steve A
I use mikroC PRO and made some products for my company. But now a days I am shifting to ATMEL STUDIO6.

Thnx All