Skip to content

Instantly share code, notes, and snippets.

@montyr75
Last active January 5, 2023 02:55
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save montyr75/09b5dc9a20ba01955872 to your computer and use it in GitHub Desktop.
Save montyr75/09b5dc9a20ba01955872 to your computer and use it in GitHub Desktop.
Find the last day of the current month with Dart's DateTime class.
final now = DateTime.now();
final lastDayOfMonth = DateTime(now.year, now.month + 1, 0);
print("${lastDayOfMonth.month}/${lastDayOfMonth.day}");
@bloodtearvn
Copy link

if now.month + 1>12 what happend?

@montyr75
Copy link
Author

DateTime handles it correctly

@marslannasr7koncepts
Copy link

DateTime handles it correctly

Thanks for last day of month code its working fine can you tell me about first day of current month code I am trying but not able to get current month first date.

@montyr75
Copy link
Author

can you tell me about first day of current month code I am trying but not able to get current month first date.

Umm... Wouldn't it just be DateTime(now.year, now.month, 1) ?

@marslannasr7koncepts
Copy link

marslannasr7koncepts commented Jul 28, 2021

can you tell me about first day of current month code I am trying but not able to get current month first date.

Umm... Wouldn't it just be DateTime(now.year, now.month, 1) ?

Thanks I have done that but thanks for help Appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment