cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
lipster26
Frequent Visitor

First day of the year and last day of the month

Is there a way to obtain the first day of the year and last day of the month from the Get Current date and time tool?

2 REPLIES 2
MichaelAnnis
Super User
Super User

Here's a sample of a GETDATES subflow I keep in almost all my flows and adjust as needed:

 

MichaelAnnis_0-1633368044100.png

 

Anonymous
Not applicable

Hello @lipster26 

 

You can use actions "Convert datetime to text", "Convert text to datetime" and "Add to datetime" for this kind of purpose.

 

Please refer my sample flow in screenshot and code snippet below:

 

 

shindomo_0-1633373683645.png

 

DISABLE Text.ToDateTime Text: $'''2021-05-31''' DateTime=> CurrentDate
DateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> CurrentDate
# The first day of the year
Text.FromCustomDateTime DateTime: CurrentDate CustomFormat: $'''yyyy-01-01''' Result=> FirstDayOfTheYearText
Text.ToDateTime Text: FirstDayOfTheYearText DateTime=> FirstDayOfTheYear
# The last day of the month
DateTime.Add DateTime: CurrentDate TimeToAdd: 1 TimeUnit: DateTime.TimeUnit.Months ResultedDate=> NextMonthOfToday
Text.FromCustomDateTime DateTime: NextMonthOfToday CustomFormat: $'''yyyy-MM-01''' Result=> FirstDayOfNextMonthText
Text.ToDateTime Text: FirstDayOfNextMonthText DateTime=> FirstDayOfNextMonth
DateTime.Add DateTime: FirstDayOfNextMonth TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> LastDayOfThisMonth
# Display result
Display.ShowMessage Message: $'''%FirstDayOfTheYear%
%LastDayOfThisMonth%''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed

 

Thank you.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,574)