Fatima ELKADDOURI
Fatima ELKADDOURI

Reputation: 185

How to get the previous date ( dd/mm/yy) in flutter

I would like to display the previous date How do I do that?

i used this methode for display the date of today, i also want to display the previous date.

  static final DateTime now = DateTime.now();
  static final DateFormat formatter = DateFormat('dd-MM-yyyy');
  final String formatted = formatter.format(now);

Upvotes: 3

Views: 1457

Answers (2)

Jaskirat Singh
Jaskirat Singh

Reputation: 79

You can add or subtract values

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

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

Upvotes: 1

Subair K
Subair K

Reputation: 1880

final now = DateTime.now();
final today = DateTime(now.year, now.month, now.day);
final yesterday = DateTime(now.year, now.month, now.day - 1);
final tomorrow = DateTime(now.year, now.month, now.day + 1);

Upvotes: 3

Related Questions