0

I am trying to get the current day then getting the day before it, how can I get that date then convert it into a String?

DateTime now = new DateTime.now();

3 Answers3

1

You can do this by doing:

   DateTime.now().subtract(Duration(days:1))

Source: https://api.flutter.dev/flutter/dart-core/DateTime-class.html

Risheek Mittal
  • 1,077
  • 2
  • 18
0

You can do this :

DateTime now = DateTime.now();
DateTime nowMinus1Day = now. subtract(const Duration(days: 1));
print(nowMinus1Day.toIso8601String());
VincentDR
  • 696
  • 3
  • 15
0

you can try this

var now = DateTime.now();
var startDate= now.subtract(Duration(days: 1));
print(startDate);
Rahul Pandey
  • 520
  • 3
  • 15