---
name: "timeradd"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/timeradd"
---

# timeradd(3)

operations on timevals and timespecs

## NAME

**timeradd**, **timersub**, **timerclear**, **timerisset**, **timercmp**, **timespecadd**, **timespecsub**, **timespecclear**, **timespecisset**, **timespeccmp** – operations on timevals and timespecs

## SYNOPSIS

**#include \<sys/time.h\>**

*void*\

**timeradd**(*struct timeval \*a*, *struct timeval \*b*, *struct timeval \*res*);

*void*\

**timersub**(*struct timeval \*a*, *struct timeval \*b*, *struct timeval \*res*);

*void*\

**timerclear**(*struct timeval \*tvp*);

*int*\

**timerisset**(*struct timeval \*tvp*);

*int*\

**timercmp**(*struct timeval \*a*, *struct timeval \*b*, *CMP*);

*void*\

**timespecadd**(*struct timespec \*a*, *struct timespec \*b*, *struct timespec \*res*);

*void*\

**timespecsub**(*struct timespec \*a*, *struct timespec \*b*, *struct timespec \*res*);

*void*\

**timespecclear**(*struct timespec \*ts*);

*int*\

**timespecisset**(*struct timespec \*ts*);

*int*\

**timespeccmp**(*struct timespec \*a*, *struct timespec \*b*, *CMP*);

## DESCRIPTION

These macros are provided for manipulating *timeval* and *timespec* structures for use with the [clock\_gettime(2)](/clock_gettime/2.md), [clock\_settime(2)](/clock_settime/2.md), [gettimeofday(2)](/gettimeofday/2.md) and [settimeofday(2)](/settimeofday/2.md) calls. The *timeval* structure is defined in ⟨sys/time.h⟩ as:

```
struct timeval {
	long	tv_sec;		/* seconds since Jan. 1, 1970 */
	long	tv_usec;	/* and microseconds */
};
```

And the *timespec* structure is defined in ⟨time.h⟩ as:

```
struct timespec {
	time_t tv_sec;		/* seconds */
	long   tv_nsec;		/* and nanoseconds */
};
```

**timeradd**() and **timespecadd**() add the time information stored in *a* to *b* and store the result in *res*. The results are simplified such that the value of *res-\>tv\_usec* or *res-\>tv\_nsec* is always less than 1 second.

**timersub**() and **timespecsub**() subtract the time information stored in *b* from *a* and store the result in *res*.

**timerclear**() and **timespecclear**() initialize their argument to midnight (0 hour) January 1st, 1970 (the Epoch).

**timerisset**() and **timespecisset**() return true if their argument is set to any time value other than the Epoch.

**timercmp**() and **timespeccmp**() compare *a* to *b* using the comparison operator given in *CMP*, and return the result of that comparison.

## SEE ALSO

[clock\_gettime(2)](/clock_gettime/2.md), [gettimeofday(2)](/gettimeofday/2.md)

## HISTORY

The **timeradd**() family of macros were imported from NetBSD 1.1, and appeared in FreeBSD 2.2.6. The **timespecadd**() family of macros were imported from NetBSD 1.3 into FreeBSD 3.0, though they were not exposed to userland until FreeBSD 12.0.
