2

I have the below info:

final startDateTime = DateTime(2020, 7, 6, 18, 00);
final endDateTime = DateTime(2020, 7, 7, 19, 00);
final currentDateTime = DateTime.now();

How do I find if currentDateTime is between startDateTime and endDateTime.

Jyo
  • 421
  • 1
  • 7
  • 20
  • Does this answer your question? [Flutter: Finding Difference Between Two Dates](https://stackoverflow.com/questions/52713115/flutter-finding-difference-between-two-dates) – Marcin Orlowski Jul 06 '20 at 06:29

2 Answers2

8

Define a method:

bool isCurrentDateInRange(DateTime startDate, DateTime endDate) {
  final currentDate = DateTime.now();
  return currentDate.isAfter(startDate) && currentDate.isBefore(endDate);
}

Use it like:

var isDateInRange = isCurrentDateInRange(startDate, endDate);
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
0
if (currentDateTime.isAfter(startDateTime) && currentDateTime.isBefore(endDateTime)) {
    ...
}
Hassan Saleh
  • 964
  • 7
  • 12