web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / fill date field with t...
Power Automate
Answered

fill date field with the first day of the month

(0) ShareShare
ReportReport
Posted on by 27

Hello community

Using power automate desktop i have to fill two date fields, knowing that for the first field it should be field with the first day of the month and the second with the actual day. for example if the second date field is filled with "06.06.2023" (the actual day) then the first date field should contain "01.06.2023"

and the flow will be excecuted daily .

How can i do that ?

I have the same question (0)
  • kinuasa Profile Picture
    799 Most Valuable Professional on at

    Hi,
    "Get current date and time" and "Add to datetime" actions allow you to get the current date and time, as well as the first and last day of the month.
    "Convert datetime to text" action allows you to change the date display format.

     

    1. Get current date and time Action
       Retrieve: Current date and time or Current date only
       Time zone: System time zone
       Variables produced: %CurrentDateTime%
    2. Add to datetime Action
       Datetime: %CurrentDateTime%
       Add: %-CurrentDateTime.Day + 1%
       Time unit: Days
       Variables produced: %FirstDateTimeOfMonth%
    3. Add to datetime Action
       Datetime: %FirstDateTimeOfMonth%
       Add: 1
       Time unit: Months
       Variables produced: %EndDateTimeOfMonth%
    4. Add to datetime Action
       Datetime: %EndDateTimeOfMonth%
       Add: -1
       Time unit: Days
       Variables produced: %FirstDateTimeOfMonth% -> %EndDateTimeOfMonth%
    5. Convert datetime to text Action
       Datetime to convert: %CurrentDateTime%
       Format to use: Custom
       Custom Format: dd.MM.yyyy
       Variables produced: %FormattedCurrentDate%
    6. Convert datetime to text Action
       Datetime to convert: %FirstDateTimeOfMonth%
       Format to use: Custom
       Custom Format: dd.MM.yyyy
       Variables produced: %FormattedFirstDateOfMonth%
    7. Convert datetime to text Action
       Datetime to convert: %EndDateTimeOfMonth%
       Format to use: Custom
       Custom Format: dd.MM.yyyy
       Variables produced: %FormattedEndDateOfMonth%

     

    Regards,
    kinuasa

     

    The code below is a sample flow:

     

    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
    DateTime.Add DateTime: CurrentDateTime TimeToAdd: -CurrentDateTime.Day + 1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> FirstDateTimeOfMonth
    DateTime.Add DateTime: FirstDateTimeOfMonth TimeToAdd: 1 TimeUnit: DateTime.TimeUnit.Months ResultedDate=> EndDateTimeOfMonth
    DateTime.Add DateTime: EndDateTimeOfMonth TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> EndDateTimeOfMonth
    Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''dd.MM.yyyy''' Result=> FormattedCurrentDate
    Text.ConvertDateTimeToText.FromCustomDateTime DateTime: FirstDateTimeOfMonth CustomFormat: $'''dd.MM.yyyy''' Result=> FormattedFirstDateOfMonth
    Text.ConvertDateTimeToText.FromCustomDateTime DateTime: EndDateTimeOfMonth CustomFormat: $'''dd.MM.yyyy''' Result=> FormattedEndDateOfMonth

     

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    While this is great, it actually includes calculating the end date of the month, which the OP does not need. They need the first day of the month and the current date. So, the following code will do the trick (can be copied and pasted directly to PAD to create all the actions):

    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
    DateTime.Add DateTime: CurrentDateTime TimeToAdd: -CurrentDateTime.Day + 1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> FirstDateTimeOfMonth
    Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''dd.MM.yyyy''' Result=> FormattedCurrentDate
    Text.ConvertDateTimeToText.FromCustomDateTime DateTime: FirstDateTimeOfMonth CustomFormat: $'''dd.MM.yyyy''' Result=> FormattedFirstDateOfMonth

     

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • BlueBirdBKE Profile Picture
    27 on at

    i tried it for today and it give this , which not correct , idont know where does the rpoblem comes , however i can see that there is two varaible with the same name ( Variables produced: %FirstDateTimeOfMonth%   for step 2 and 4) could the problem comes from that

    Capture.PNG
  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    You clearly used the code the other person posted. Mine does not contain the EndDateTimeOfMonth at all, because you don't need it.

  • BlueBirdBKE Profile Picture
    27 on at

    thank you it worked 

     

  • kinuasa Profile Picture
    799 Most Valuable Professional on at

    I made a copy and paste error. Sorry.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 862

#2
Valantis Profile Picture

Valantis 738

#3
Haque Profile Picture

Haque 553

Last 30 days Overall leaderboard