How to Get Last Month Date In Flutter ?

· 2 min read
How to Get Last Month Date In Flutter
How to Get Last Month Date In Flutter

Generally, a user requires to display Date and Time in the desired format as per client requirement So in this article we will go through How to Get Last Month Date In Flutter?

How to Get Last Month Date In Flutter?

User can use it like the below:

var prevMonth = new DateTime(date.year, date.month - 1, date.day);

with

var date = new DateTime(2018, 1, 13);

The user will get the date in the below format.

2017-12-13

It’s usually a good idea to convert to UTC and then back to local date/time before doing date calculations to avoid issues with daylight saving and time zones.

We can use the subtract method to get past month date.

DateTime pastMonth = DateTime.now().subtract(Duration(days: 30));

Conclusion:

In this article, we have been through How to et Last Month Date In Flutter?

Keep Learning !!! Keep Fluttering !!!

Still, need support for Flutter Development? Do contact us.

FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

FlutterAgency.com is one of the most popular online portal dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge on Flutter.

1 comment

  1. this is good but , days are change every month just like 30,31 and in FEB 28 or 27. my suggestion create new function to subtract with month just like a day duration.

Leave a Reply