avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Monday July 22, 2024, 3:31 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: NANY 2013 Submission - tmdiff - Formatted Output of Time Differences in C  (Read 9629 times)


  • Developer
  • Joined in 2005
  • ***
  • Posts: 1,187
    • View Profile
    • Donate to Member
NANY 2013 Entry Information

Application Nametmdiff
Short DescriptionA collection of C functions to aid in output of time differences
Supported OSesAnything with a decent C compiler.
Web Page
Version Historyhttps://bitbucket.or...n/tmdiff/commits/all


This is an attempt at solving the problem of formatting the difference between two points in time in a manner similar to the strftime() function. It was based on a discussion about PBoL.

The problem is; given a start date and time, and an end date and time, format a string with values showing the difference in years, months, days, hours, minutes, and seconds between the two.

Because months and years contain a varying number of days, we cannot simply compute these from difftime().

For instance, the difference between Jan 31st and Mar 1st is sometimes 29 days, sometimes 30 days, but always one month and one day. The difference between Jul 2nd and Aug 1st is 30 days, but not a month.

For a more detailed description of the problem, check this blog post.


tmdiff() is a low-level function that does the actual work of computing the time difference between two tm structs.

sftmdiff() and wsftmdiff() provide formatted output of the time difference between two tm structs.

asctmdiff() and wasctmdiff() provide a more generic textual representation.
« Last Edit: December 29, 2012, 01:20 PM by Jibz »


  • Developer
  • Joined in 2005
  • ***
  • Posts: 1,187
    • View Profile
    • Donate to Member


  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,911
    • View Profile
    • Mouser's Software Zone on
    • Read more about this member.
    • Donate to Member
Glad to see you participating in NANY this year, Jibz!
And yes, for anyone wondering, although this is a library for programmers, this qualifies as a NANY under our loose guidelines.


By the way, I love the way your bitbucket documentation page looks.  Very readable.