How to compare two DateTime values in Flutter (dart) using IF condition?
Solution 1:
Convert into DateTime
and use isAfter
or isBefore
to compare
DateTime date1 = DateTime.now();
System.out.println(date1);
DateTime date2 = DateTime.now().plusDays(1);
System.out.println(date2);
System.out.println(date1.isBefore(date2)); //true
System.out.println(date1.isAfter(date2)); //false
Solution 2:
DateFormat dateFormat = DateFormat.jm();// this is the format like(5:08 PM)
DateTime now = DateTime.now();// current time
DateTime open = dateFormat.parse(time); // time is dynamic value database
open = DateTime(now.year, now.month, now.day, open.hour, open.minute);
// here your condition
if(now.isAfter(open)){
// task here
}else{
}