0

I need This current weeks day name, with the date like (01/12/2020). I can select the data, so that I can use the data further.

  • see below: https://stackoverflow.com/questions/54371874/how-get-the-name-of-the-days-of-the-week-in-dart – Arash Mohammadi Sep 12 '20 at 04:32
  • 1
    no is not, i need select option of 7 days. – david david Sep 12 '20 at 04:44
  • 1
    What does "select option of 7 days" mean? Your question is very unclear. As stated, you want to take a date (e.g. January 12, 2020) and derive the weekday name ("Sunday"), which is what the cited question already answers. It sounds like you want something else? – jamesdlin Sep 12 '20 at 05:55

2 Answers2

1

/////////////////////////////////////////////////////// BUILD YOUR OWN ///////////////////////////////////////////////

Add this to your package's pubspec.yaml file:

      dependencies:
          intl: ^0.16.1

Import the package in the dart file

    import 'package:intl/intl.dart';

    ...

    var dateString = '01/12/2020';
    var date = DateFormat('d/M/yyyy').parse(dateString);


    List<String> daysInWeek=['Monday', 'Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday',];
    print(daysInWeek[date.weekday-1]); 
Amon C
  • 1,710
  • 9
  • 17
-1

I think what you're wanting is the actual name of the day of the week. In that case, this should do the trick:

  var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
  var day = DateTime.parse('2020-09-12').weekday;
  print(days[day]); // prints "Saturday"

Try pasting this code in dartpad to see how it works

loganrussell48
  • 1,656
  • 3
  • 15
  • 23