flutter compare dates

74

 //the birthday's date
 final birthday = DateTime(1967, 10, 12);
 final date2 = DateTime.now();
 final difference = date2.difference(birthday).inDays;
DateTime dt1 = DateTime.parse("2021-12-23 11:47:00");
DateTime dt2 = DateTime.parse("2018-02-27 10:09:00");

if(dt1.compareTo(dt2) == 0){
    print("Both date time are at same moment.");
}

if(dt1.compareTo(dt2) < 0){
    print("DT1 is before DT2");
}

if(dt1.compareTo(dt2) > 0){
    print("DT1 is after DT2");
}

Comments

Submit
0 Comments