How to check a date is expired or not in Flutter?

1,304

DateTime type has handy method isBefore and isAfter to compare two DateTime objects.

For example:

final now = DateTime.now();
final expirationDate = DateTime(2021, 1, 10);
final bool isExpired = expirationDate.isBefore(now);

In this example, isExpired variable will be true if it has passed the expirationDate and false if it has not passed the expiration date.

Share:
1,304
Murali Krishnan
Author by

Murali Krishnan

Updated on December 26, 2022

Comments

  • Murali Krishnan
    Murali Krishnan over 1 year

    How can i check if a date is expired or not. for eg: if the expire date is 10/01/2021, if the user check today(09/01/2021) it should print "Not Expired", if the user check on 11/01/2021 or after the expiry days it should print "the date is expired". How can i implement this in flutter.