How to extract date dynamically using Uipath

Hi team,

If frequency is annual and month is May 2024 .
So I need 05/01/2023 to 31/12/2023.

If frequency is monthly and month is June 2024.

I need 05/01/2024 to 05/31/2024(Previous mnth).

If frequency is Quarlty and month will be 1,4,7,10
If month is 1 then I need previous 3 months like
10/01/2023 to 12/31/2023.

I need this montha and date values dynamically.

Can any one help me .

I need dynamic flow for the above query .
If frequency and month changes it will give correct values.

Hi @Baby123

To get the first date,
str_firstdate = New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString

To get the last date,
str_lastedate = New DateTime(now.Year, now.Month, DateTime.DaysInMonth(now.Year, now.Month)).ToString

Hope it helps!!

@Baby123

  1. Assign Variables:

    • Create variables to store the frequency and month values.
      • frequency (String): “Annual”, “Monthly”, “Quarterly”
      • selectedMonth (Int): The selected month (e.g., 5 for May, 6 for June, 1 for January)
  2. Switch Activity:

    • Use a Switch activity based on the frequency variable.

    Case “Annual”:

    • Inside this case, calculate the date range for an annual frequency.
    • Assign the start and end dates to variables.
      • startDate (DateTime): new DateTime(selectedYear - 1, 1, 1)
      • endDate (DateTime): new DateTime(selectedYear - 1, 12, 31)

    Case “Monthly”:

    • Inside this case, calculate the date range for a monthly frequency.
    • Assign the start and end dates to variables.
      • startDate (DateTime): new DateTime(selectedYear, selectedMonth, 1).AddMonths(-1)
      • endDate (DateTime): new DateTime(selectedYear, selectedMonth, 1).AddDays(-1)

    Case “Quarterly”:

    • Inside this case, calculate the date range for a quarterly frequency.
    • Assign the start and end dates to variables.
      • startDate (DateTime): new DateTime(selectedYear, selectedMonth, 1).AddMonths(-3)
      • endDate (DateTime): new DateTime(selectedYear, selectedMonth, 1).AddDays(-1)
  3. Log Message:

    • Use a Log Message activity to display the calculated date range.
    • Example: Log Message: "Start Date: " + startDate.ToString("MM/dd/yyyy") + ", End Date: " + endDate.ToString("MM/dd/yyyy")
  4. Further Processing:

    • Proceed with any further processing based on the calculated date range.

Could you be more elaborate, getting some confusion what is Annually and Monthly.
I am clear about Quarter.

Give me the proper input and output… @Baby123

Hope you understand!!

If frequency is annual and month is 1 (current month).

I need to fetch the date like
From date is 01/01/2023
To date is 31/12/2023.
Gap will be 1 year because frequency is annual.

If frequency monthly and month is 1 ( current month).

From date : 12/01/2023
Todate : 12/31/2023

Hi @Baby123

Please check the below workflow:
2024.xaml (24.6 KB)

Hope you understand!!

Hi @mkankatala ,

This is not crt flow .
Let me explain again
.
1). Frequency : Annual
Month : 1 (that means current month)
If frequency is annual and month is Jan2024 so, I want output like this.
Fromdate : 12/01/2023
Todate: 12/31/2023
Fromdate and todate gap will be 1 year that means annual.

2). If frequency :Monthly
Montha : 1 (current month).

Output: from date : 12/01/2023
Todate : 12/31/2023
Gap will be 1 month.

3). If frequency : Quetrly:
Month like this (1,4,7,10).

If month 1
Fromdate: 10/01/2023
Todate :12/31/2023

For example month 4 menas
From date: 01/01/2024
Todate: 03/31/2024.

Note: i want these dynamically.
Based on current month and frequency Bot will able to get fromdate and to date.

Please suggest and send me the flow of possible

The above code will satisfy the 2nd and 3rd condition, I have to change the lastDate variable expression to get the required output for the 1st condition.

I have a small doubt if the input is like below
Frequency is annual
Input is March 2024 then what is the output you want.

Hope you understand!!

Thank you I will check and let you know.

Annual output like this
Fromdate: 03/31/2023
Todate: 02/29/2024

In the first Else if block replace the Expression for the LastDate variable… @Baby123

- Assign -> LastDate = DateTime.ParseExact(Input, "MMMM yyyy", System.Globalization.CultureInfo.InvariantCulture).AddYears(1).AddDays(-1).ToString("MM/dd/yyyy")

After replacing this, the whole process is completed and all conditions got satisfied.

Hope it helps!!

1 Like

Check the below image of the required output -

If you find the solution for you query, Make my post mark as solution to close the loop.

Happy Automation!!

@Baby123

You can use this

ToDate = New DateTime(Now.Year,Now.Month,1).Adddays(-1)

FromDate = ToDate.Adddays(1).AddMonths(If(Frequency="Annual",-12,If(Frequency="Quarterly",-3,-1)))

Hope this helps

Cheers

Hi @mkankatala .

Sorry …

If frequency is Annual and months March 2024
From date is : 03/01/2023
Todate: 02/29/2024

Like this
Previous year March 1st 2023 to Feb last date current year(2024)

Okay @Baby123

Then change the FirstDate and LastDate Variables expressions as below in the First Else If condition which is checking for annual.

- Assign -> FirstDate = DateTime.ParseExact(Input, "MMMM yyyy", System.Globalization.CultureInfo.InvariantCulture).AddYears(-1).ToString("MM/dd/yyyy")

- Assign -> LastDate = DateTime.ParseExact(Input,"MMMM yyyy",System.Globalization.CultureInfo.InvariantCulture).AddDays(-1).ToString("MM/dd/yyyy")

Check the below output,

Hope it helps and Happy Automation!!

For monthly also I have new change
If month is Aug 2024 .

I need previous month 1st date and. Last date .
Output:
From date: 07/01/2024
Todate : 07/31/2024

If month is Aug 2025

Output will be :
07/01/2025
07/31/2025.

Make sure year also change based on the input

Okay @Baby123

Then change the FirstDate and LastDate Variables expressions as below in the First Else If condition which is checking for Monthly.

- Assign -> FirstDate = DateTime.ParseExact(Input, "MMMM yyyy", System.Globalization.CultureInfo.InvariantCulture).AddMonths(-1).ToString("MM/dd/yyyy")

- Assign -> LastDate = DateTime.ParseExact(Input,"MMMM yyyy",System.Globalization.CultureInfo.InvariantCulture).AddDays(-1).ToString("MM/dd/yyyy")

Check the output -

If you got the solution for your query, make my post mark as solution to close the loop.
If you have any other modifications required, please close this loop and Post your query in the new post.

Hope you understand!!

Hi @mkankatala ,

Quetrly condition not working.

I am getting first date correctly but I am not getting last date properly.

Month : April 2024
I am getting first date : 01/01/2024
But last date will be 03/31/2024
But I am getting 02/28/2024.

first date : DateTime.ParseExact(Input, “MMMM yyyy”, CultureInfo.InvariantCulture).AddMonths(-3).ToString(“MM/dd/yyyy”)

Last date: DateTime.ParseExact(Input, “MMMM yyyy”, CultureInfo.InvariantCulture).AddMonths(-1).AddDays(-1).ToString(“MM/dd/yyyy”)

Please suggest

Okay @Baby123

Then change the LastDate Variables expressions as below in the Third Else If condition which is checking for Quarterly.

- Assign -> LastDate = DateTime.ParseExact(Input,"MMMM yyyy",System.Globalization.CultureInfo.InvariantCulture).AddDays(-1).ToString("MM/dd/yyyy")

Check the below output -

Note : There is small change in the code at one assign activity,
Now it is like below,

- Assign -> QuarterMonths = {01,04,10}

Change as below,

- Assign -> QuarterMonths = {01,04,07,10}

Hope it helps!!

1 Like

Hey @Baby123
please try this workflow:
BlankProcess87.zip (2.8 KB)

Hello @Baby123,

Hope you are doing well!

please have a look on the attached code if this helps ultimately.

DynamicDateExtract.xaml (32.0 KB)