Home > OS >  Get correct date from excell on flutter
Get correct date from excell on flutter

Time:06-20

Hello guys I'm having a little hard time figuring this out.

So I have a small excell that I'm putting some information there(adding and requesting)

The problem is when I'm trying to get the date as string, and add it as DateTime.

Always the same error "Invalid Date Format"-

I have my dates on excell, as Simple Text saved as "20-06-2022", and displaying that on flutter with "user[index].date", all ok. The problem is that I want to compare the dates with a random day.

I've tried
DateTime.parse(users[index].date); // not working
Text(users[index].date); // not working ( shows random numbers as 44734)

CodePudding user response:

The DateTime.parse method only accepts specific formats that are listed in the documentation.

Since yours is not one of those, you need to create a DateFormat instance of your own and use that one to parse

void main() {
  final text = '20-06-2022';
  
  final format = DateFormat('dd.MM.yyyy');
  
  final date = format.parse(text);
  
  print(date);
}
  • Related