Operating System - HP-UX
1836987 Members
2391 Online
110111 Solutions
New Discussion

Three C programs for your pleasure - timediff

 
Joel Shank
Valued Contributor

Three C programs for your pleasure - timediff


I have noticed several threads referring to time manipulation such as adding or subtracting days or months from a date, getting the difference between two dates, etc. I have written 3 C programs that act as commands that perform these functions that Iâ d like to share with the forum. They have been compiled on HPUX 10.20, 11.00 and 11I as well as AIX 4.1 and 4.3, with one minor modification (documented in the code). Since they all use standard UNIX header files, these should also compile on other UNIX flavors.

Since I can only attach one file per thread, I will make three threads, one for each program.

This program is timediff. If entered without any arguments, only its syntax is displayed.

The syntax of timediff is:

timediff [-l] [-h] â Fromâ [â Toâ ]

The switch â l (lower case letter el) is used to print the difference in a long format:
nnn Days, nn Hours, nn Minutes, nn Seconds
(â nnn Days,â is not included if the day count is zero)

If the long format is not specified, the difference is printed as:
nnn:hh:mm:ss
(â nnn:â is not included if the day count is zero)

The â h switch (hour format) will convert the elapsed days, if any, to hours.

â Fromâ and â Toâ specify the start and end date/times respectively and may be specified in one of several formats:
ï · Long Date format, as returned by â dateâ or â date â +câ â
ï · Short Date format: â mm/dd/yy[yy] hh:mm:ssâ
ï · Time format: hh:mm:ss

The Date formats must be enclosed in quotes. As with the other programs, if a 2-digit year is specified in the Short Date format, it is assumed to be an offset from the year 2000.

â Toâ is optional. If not specified, the current date is used.

Space limitations prevent me from giving an expanded syntax, so look at the
1 REPLY 1
Nicolas Dumeige
Esteemed Contributor

Re: Three C programs for your pleasure - timediff

Joel

Man, what kind of keyboard do you have ?!

But thank for the program. Can be usefull when using a timestamp flag for last run and thing like this.

Cheers

Nicolas


All different, all Unix