[英]Flutter/Dart Firestore query: How do I get all docs where today falls between start/end dates in doc?
[英]hello i need to compare 2 dates like start date and end date and if i select a wednesday i need all wednesdays occuring between these dates
我有一個場景,用戶選擇開始日期和結束日期,用戶還選擇一個特定的日期,我需要顯示該特定日期和它們之間的日期。
我嘗試了 Intl package 差異方法但沒有用
你可以使用這個方法。 采用開始和結束日期以及工作日。 注意,可以將 3 作為 int 或 'DateTime.wednesday' 作為參數傳入。
List<DateTime> getAllDatesOfAWeekday(
{required DateTime startDate,
required DateTime endDate,
required int weekday}) {
List<DateTime> allDates = [];
for (int i = 0; i <= endDate.difference(startDate).inDays; i++) {
if (startDate.add(Duration(days: i)).weekday == weekday) {
allDates.add(startDate.add(Duration(days: i)));
}
}
return allDates;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.