W3cubDocs

/Dart 2

subtract method

DateTime subtract (Duration duration)

Returns a new DateTime instance with duration subtracted from this.

DateTime today = new DateTime.now();
DateTime fiftyDaysAgo = today.subtract(new Duration(days: 50));

Notice that the duration being subtracted is actually 50 * 24 * 60 * 60 seconds. If the resulting DateTime has a different daylight saving offset than this, then the result won't have the same time-of-day as this, and may not even hit the calendar date 50 days earlier.

Be careful when working with dates in local time.

Implementation

external DateTime subtract(Duration duration);

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.5.0/dart-core/DateTime/subtract.html