# man > Date::Manip::Delta

---
type: CommandReference
command: Date::Manip::Delta
mode: perldoc
section: ""
source: perldoc
---

## Quick Reference

- `$delta = new Date::Manip::Delta;` — create a new delta object
- `$err = $delta->parse($string, \%opts);` — parse a delta string (options: mode, nonorm, type)
- `$err = $delta->set(\%opts);` — set fields of a delta (fields: y, M, w, d, h, m, s; options: mode, type, nonorm)
- `$val = $delta->value();` — return delta as string or list of fields
- `$delta->convert($to);` — convert between exact, semi, approx types
- `$flag = $delta1->cmp($delta2);` — compare two deltas (-1, 0, 1)
- `$out = $delta->printf($format);` — format delta using printf directives
- `$flag = $delta->type($op);` — test if delta is business/standard/exact/semi/approx/estimated

## Name

Date::Manip::Delta - Methods for working with deltas (time intervals)

## Synopsis

perl
use Date::Manip::Delta;
$delta = new Date::Manip::Delta;
## Options (Methods)

### `new`
- `$delta = new Date::Manip::Delta;` — create a new delta object. Also accepts optional config, date, delta, or recur arguments.

### `parse`
- `$err = $delta->parse($string, \%opts);` — parse a delta string. Recognized options:
  - `mode`: `standard` or `business`
  - `nonorm`: 0/1 (1 to skip normalization)
  - `type`: `exact`, `semi`, `approx`, `estimated`
- Backward-compatible form: `$delta->parse($string, $business, $no_normalize);` (deprecated)

### `set`
- `$err = $delta->set(\%opts);` — set one or more fields. Options:
  - `delta`, `business`, `standard`: array ref [Y,M,W,D,H,MN,S]
  - `y`, `M`, `w`, `d`, `h`, `m`, `s`: single field value
  - `mode`: `business` or `standard`
  - `type`: `exact`, `semi`, `estimated`, `approx`
  - `nonorm`: 0/1
- Backward-compatible: `$delta->set($field, $val, $no_normalize);` (deprecated)

### `printf`
- `$out = $delta->printf($format);` — format delta using printf directives. See dedicated section.
- `@out = $delta->printf(@formats);` — list context.

### `calc`
- Refer to `Date::Manip::Calc` for arithmetic operations.

### `type`
- `$flag = $delta->type($op);` — test type:
  - `business` / `standard`: returns 1 if business/standard
  - `exact`, `semi`, `approx`, `estimated`: returns 1 if delta matches that type

### `value`
- `$val = $delta->value();` — scalar: printable string (like `%Dt`). List: (Y,M,W,D,H,MN,S).

### `convert`
- `$delta->convert($to);` — convert to `exact`, `semi`, or `approx`. Result is normalized. Only exact→semi→approx supported; reverse is deprecated.

### `cmp`
- `$flag = $delta1->cmp($delta2);` — compare two deltas (approximate). Returns -1, 0, 1. Both must be valid and same mode (business/standard). Returns `undef` on error.

### `input`
- `$str = $delta->input();` — return the string originally parsed.

### `base`, `config`, `err`, `tz`, `is_date`, `is_delta`, `is_recur`
- Inherited from `Date::Manip::Obj`. See that module for details.

## Examples

### Parsing a delta
perl
$delta = new Date::Manip::Delta;
$err = $delta->parse("+1:2:3:4:5:6:7");
$err = $delta->parse("4 hours 3 minutes ago", { mode => "business" });
### Setting fields
perl
$delta->set({ y => 1, m => 2, w => 3, d => 4, h => 5, m => 6, s => 7 });
$delta->set({ delta => [1,2,3,4,5,6,7], mode => "standard", type => "approx" });
### Converting type
perl
$delta->convert("semi");   # exact -> semi-exact
### Comparing deltas
perl
$delta1 = new Date::Manip::Delta;
$delta2 = new Date::Manip::Delta;
$delta1->parse("0:0:0:0:1:0:0");   # 1 hour
$delta2->parse("0:0:0:0:0:60:0");  # 60 minutes
$flag = $delta1->cmp($delta2);     # 0 (equal)
### Formatting with printf
perl
$delta->printf("|%Dt|");          # => "+1:2:+3:+4:5:6:7"
$delta->printf("|%+Dyd|");        # => "+1:+2:+3:+4"
$delta->printf("|%.4Myw|");       # => "14.6900" (months)
## See Also

- [Date::Manip](http://localhost/phpMan.php/perldoc/Date%3A%3AManip/markdown) — main module documentation
- [Date::Manip::Obj](http://localhost/phpMan.php/perldoc/Date%3A%3AManip%3A%3AObj/markdown) — base class methods
- [Date::Manip::Calc](http://localhost/phpMan.php/perldoc/Date%3A%3AManip%3A%3ACalc/markdown) — delta arithmetic
- [Date::Manip::Lang::English](http://localhost/phpMan.php/perldoc/Date%3A%3AManip%3A%3ALang%3A%3AEnglish/markdown) — field name strings for English
- [Date::Manip::Problems](http://localhost/phpMan.php/perldoc/Date%3A%3AManip%3A%3AProblems/markdown) — bug reports and questions

## Additional Delta Notations

- Compact: `Y:M:W:D:H:MN:S` (colon-separated, 1–7 fields, signs optional)
- Expanded: `+4 hours +3mn -2second` (field names as per language document)
- Keywords: `in` (positive), `ago` (reverses signs), `business` (business mode)
- Order: Y M W D H MN S
- Fractional values allowed (e.g., `1.25 days`) – converted using estimated relationships.

## Printf Directives

- `%%` — literal `%`
- `%[+][pad][width]Xv` — single field value (X = y,M,w,d,h,m,s)
- `%[+][pad][width][.precision]XYZ` — value of fields Y through Z in terms of X
- `%[+][pad][width]Dt` — entire delta
- `%[+][pad][width]DXY` — delta from field X to Y (inclusive)
- `+` forces sign on all fields; `pad` = `<` (left), `>` (right), `0` (zero-fill)