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 / How to get particular ...
Power Automate
Answered

How to get particular date

(1) ShareShare
ReportReport
Posted on by 52

Hi ,below is my use case

I want to key in date like ....getcurrentdatetime go to 2 month back and get lasdate of that month .

For example - today is  8july2024 ...if we are in July month going 2 month back complete July complete June i.e 1june 2024 then again get last date of previous month i.e 31may2024 

So my final result should be 31may2024

 

 

  • VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    Hi @aggneha9821 ,

     

    Please find the solution.

     

    Use Run Vbscript action to get the above scenario as shown in above image.

    VishnuReddy1997_0-1720408654349.png

     

    VBScript Code:

    ' Get the current date
    Dim currentDate
    currentDate = Now
    
    ' Subtract 2 months
    Dim pastDate
    pastDate = DateAdd("m", -1, currentDate)
    
    ' Get the first day of the month 2 months back
    Dim firstDayOfMonth
    firstDayOfMonth = DateSerial(Year(pastDate), Month(pastDate), 1)
    
    ' Subtract one day to get the last day of the previous month
    Dim lastDayOfPreviousMonth
    lastDayOfPreviousMonth = DateAdd("d", -1, firstDayOfMonth)
    
    ' Display the result
    MsgBox "The last date of the month two months back is: " & lastDayOfPreviousMonth

     

    (Note:- if you got your solution you can mark as solution and gives kudos)


    Thanks & Regards

    Vishnu Reddy

     

  • aggneha9821 Profile Picture
    52 on at

    @VishnuReddy1997 could u plz tell any other method without using scripting 

  • CKN Profile Picture
    58 on at

    Get the current date, store in variable 'today'

    assign a new variable 'NewDate' to 1/%today.month%-1/%today.year%

    add -1 days to NewDate and you have your result

  • Verified answer
    VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    Hi @aggneha9821 ,

     

    Please find the solution.

    VishnuReddy1997_0-1720414265900.png

     

    Code:

    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> TodaysDate
    SET LastMonth TO $'''1/%TodaysDate.Month - 1%/%TodaysDate.Year%'''
    DateTime.Add DateTime: LastMonth TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ResultedDate

     

    (Note:- if you got your solution you can mark as solution and gives kudos)


    Thanks & Regards

    Vishnu Reddy

  • kanha123_456 Profile Picture
    43 on at

    @VishnuReddy1997 by this logic am getting 1april2024 .....not 31may2024( which is actual result)

  • VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    Hi @kanha123_456 ,

     

    I have run the same code and you can see the result i am getting 31-05-2024 means 31-May-2024.

    VishnuReddy1997_0-1720417149575.png

    Please try to copy and paste the code provide by me at the below reply.

     

    (Note:- if you got your solution you can mark as solution and gives kudos)


    Thanks & Regards

    Vishnu Reddy

     

  • kanha123_456 Profile Picture
    43 on at

    @VishnuReddy1997 plz see below screenshot . i copied ur code only could u plz let me know where i am doing wrong

    kanha123_456_0-1720417640580.png

    code: DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> TodaysDate
    SET LastMonth TO $'''1/%TodaysDate.Month - 1%/%TodaysDate.Year%'''
    DateTime.Add DateTime: LastMonth TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ResultedDate

  • kanha123_456 Profile Picture
    43 on at

    @CKN getting syntax error in 3rd step

  • VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    Hi @kanha123_456 ,

     

    Even if copy paste your code also i am getting 31st May only .

    Then Just try with VBscript methods once and let me know.

     

    (Note:- if you got your solution you can mark as solution and gives kudos)

     

    Regards,

    Vishnu Reddy

  • kanha123_456 Profile Picture
    43 on at

    @VishnuReddy1997 do u have any idea then why m not getting same date ...in lastmonth i am getting 1june2024 only but in resultdated i am getting wrong .

     

    i have tried vbscripit and its working fine but in project we dont have permissiion to use scripting

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 233 Super User 2026 Season 2

#2
David_MA Profile Picture

David_MA 227 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 178

Last 30 days Overall leaderboard