# man > Date::Manip::Calc

---
type: CommandReference
command: Date::Manip::Calc
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference

- `$delta = $date1->calc($date2, $subtract, $mode)` — date‑date calculation (delta between two dates)
- `$date2 = $date1->calc($delta, $subtract)` — date‑delta calculation (add/subtract delta to/from a date)
- `$delta3 = $delta1->calc($delta2, $subtract, $no_normalize)` — delta‑delta calculation (add/subtract two deltas)
- `$mode` values: `exact`, `semi`, `approx`, `business`, `bsemi`, `bapprox`
- `$subtract` can be 0 (add), 1 (subtract), or 2 (reverse direction) – important for approximate deltas
- `$no_normalize` can be `'nonormalize'` or a non‑zero value to prevent normalization of the result
- Business mode respects work week, work day, and holidays; non‑business mode treats all days as full length
- Exact deltas use only hours, minutes, seconds; semi‑exact adds days/weeks (same‑time‑next‑day); approximate adds years/months

## Name

Date::Manip::Calc - describes date calculations

## Synopsis

perl
$delta  = $date->calc($date2 [,$subtract] [,$mode]);
$date2  = $date->calc($delta [,$subtract]);
$date2  = $delta->calc($date1 [,$subtract]);
$delta3 = $delta1->calc($delta2 [,$subtract] [,$no_normalize]);
Date calculations are complicated because fields like months and days have variable lengths. This module provides three levels of precision: exact (h:m:s), semi‑exact (days/weeks + h:m:s), and approximate (all fields). Two categories are supported: non‑business (standard) and business (work‑week, work‑day, holidays).

## Options

### Method arguments

- `$date1`, `$date2` — valid `Date::Manip::Date` objects
- `$delta`, `$delta1`, `$delta2` — valid `Date::Manip::Delta` objects
- `$subtract` — controls direction of calculation:
  - `0` (default) — result = date2 + delta (or delta1 + delta2)
  - `1` — result = date1 - delta (or delta1 - delta2)
  - `2` — only for approximate date‑date or date‑delta; reverses the relationship (e.g. find the date that, when added to delta, gives date1)
- `$mode` — only for date‑date calculations; one of the mode values below
- `$no_normalize` — `'nonormalize'` or any non‑zero value; prevents normalization of the delta result (requires `$subtract` even if 0)

### Mode values

- `exact` — non‑business, exact (h:m:s only)
- `semi` — non‑business, semi‑exact (days/weeks + h:m:s)
- `approx` — non‑business, approximate (all fields)
- `business` — business, exact
- `bsemi` — business, semi‑exact
- `bapprox` — business, approximate

### Behaviour by calculation type

- **Date‑date**: mode is supplied explicitly; delta produced is of the given type.
- **Date‑delta**: mode is determined by the delta’s type (business vs. non‑business, exact vs. semi‑exact vs. approximate).
- **Delta‑delta**: mode is determined by both deltas; if one is approximate, the result is approximate; if one is business and the other is not, an error occurs.

## Examples

perl
# Exact date‑date (non‑business)
$delta = $date1->calc($date2, 0, "exact");   # 770 hours between Nov 3 2016 11:00 and Dec 5 2016 12:00

# Approximate date‑date
$delta = $date1->calc($date2, 0, "approx");  # 1 month, 2 days, 1 hour

# Date‑delta (non‑business, approximate)
$date2 = $date1->calc($delta, 0);            # add 1 year, 1 month, 1 day, 1 hour to Mar 31 2001 -> May 1 2002 13:00

# Business date‑delta with holiday
$date1 = Date::Manip::Date->new("Mon, Jun 27, 2011 12:00");
$delta = Date::Manip::Delta->new("1 week, 1 day, 1 hour");
$date2 = $date1->calc($delta, 0);            # Wed, Jul 6, 2011 09:00 (Jul 4 is a holiday)

# Delta‑delta
$delta3 = $delta1->calc($delta2, 0);         # add two deltas

# Subtraction with $subtract = 2 (approximate)
$date2 = $date1->calc($delta, 2);            # find date that, when added to $delta, gives $date1
## See Also

- [Date::Manip](https://metacpan.org/pod/Date::Manip) — main module documentation
- [Date::Manip::Date](https://metacpan.org/pod/Date::Manip::Date) — date objects
- [Date::Manip::Delta](https://metacpan.org/pod/Date::Manip::Delta) — delta objects
- [Date::Manip::Config](https://metacpan.org/pod/Date::Manip::Config) — configuration (work week, holidays)
- [Date::Manip::Problems](https://metacpan.org/pod/Date::Manip::Problems) — bug reports and questions

## Exit Codes

Not applicable; errors are returned as invalid objects with an error flag.