How to get start of or end of week in dart

You can get the weekday from the DateTime using https://api.dart.dev/stable/2.5.1/dart-core/DateTime/weekday.html and add/subtract this number from you date: void main() { final date = DateTime.parse(‘2019-10-08 15:43:03.887’); print(‘Date: $date’); print(‘Start of week: ${getDate(date.subtract(Duration(days: date.weekday – 1)))}’); print(‘End of week: ${getDate(date.add(Duration(days: DateTime.daysPerWeek – date.weekday)))}’); } DateTime getDate(DateTime d) => DateTime(d.year, d.month, d.day); UPDATE Please read and upvote the … Read more

Using DateTime properties in Code-First Entity Framework and SQL Server

You can specify the type in Fluent API: modelBuilder.Entity<Book>() .Property(f => f.DateTimeAdded) .HasColumnType(“datetime2”); This creates a datetime2(7) column in the database. If you want to finetune the precision you can use: modelBuilder.Entity<Book>() .Property(f => f.DateTimeAdded) .HasColumnType(“datetime2”) .HasPrecision(0); … for a datetime2(0) column in the DB. However, the code you have shown in your question works … Read more

Function to return date of Easter for the given year

Python: using dateutil’s easter() function. >>> from dateutil.easter import * >>> print easter(2010) 2010-04-04 >>> print easter(2011) 2011-04-24 The functions gets, as an argument, the type of calculation you like: EASTER_JULIAN = 1 EASTER_ORTHODOX = 2 EASTER_WESTERN = 3 You can pick the one relevant to the US. Reducing two days from the result would … Read more

Twig date difference

Since PHP 5.3 There is another option without to write an extension. This example show how to calc the plural day/days {# endDate and startDate are strings or DateTime objects #} {% set difference = date(endDate).diff(date(startDate)) %} {% set leftDays = difference.days %} {% if leftDays == 1 %} 1 day {% else %} {{ … Read more

How to get last midnight in Dart?

This should do the same var now = DateTime.now(); var lastMidnight = DateTime(now.year, now.month, now.day); You can use this way to get different times of this day var tomorrowNoon = DateTime(now.year, now.month, now.day + 1, 12); var yesterdaySixThirty = DateTime(now.year, now.month, now.day – 1, 6, 30); Depending on what you want can absolute values be … Read more