Hi i need to get the previous month starting date and ending date based on the present date

Hi Team,
I have one challenge please help me from this asap.

I have one excel file there is some data, one of the column contains month, quarterly, halfyearly rows. Here I need to get the previous month starting date and ending date for monthly data.
And I want the previous 3 months starting date and ending date for quarterly data.

ex for a month: today 14-02-2019 I want 01-Jan-2019 - 31-Jan-2019
ex for quarterly: today 14-02-2019 I want 01-Nov-2018 to 31-Jan-2019

please let me know solution
thanks
Udaya

1 Like

Hi @uday_kumar,

In this scenario, we can consider the starting date of present month as a reference date and comparing all other date with this date helps to obtain the dates that you have specified.

Assign type DateTime, CurrentStart = new system.DateTime(now.Year,now.Month,1)
PreviousStart = CurrentStart.AddMonths(-1)
PreviousEnd = CurrentStart.AddDays(-1)
QuarterStart = CurrentStart.AddMonths(-3)

Quarter End date and previous month end date are the same.
You can the change the date format as per your wish and enter it in the rows, like row("Month")= PreviousStart.ToString("dd-MMM-yyyy") +" to "+ PreviousEnd.ToString("dd-MMM-yyyy")

If you want to determine the previous month date and quarterly date with respect to the value in your datatable, first you have to convert the date to datetime format if it’s a string.
Assign type DateTime, RefDate= System.DateTime.ParseExact(StringDate.Trim,"dd-MM-yyyy",system.Globalization.CultureInfo.InvariantCulture)

Then you can consider this as a reference date and do the above mentioned operations.

If you have any troubles, please check the workflow Starting_&_Ending_Date.xaml (9.8 KB)

Warm regards,
Nimin

6 Likes

Hi,

Parse To datetime format: datetime.parse()
Next you can ask for the month of your object and put 1 for the day. Now you have thé first element.
For the second, you add one month and substract one day.

1 Like

Tq Team I got result. tq so much

Hello, Thank you for the information.
What if I just need the month and year of the previous month.
So, if I run the BOT today then it should give me 03.2020.

Thank you

Hi ,

I want to replace the current system date with the StringDate variable in this formula
System.DateTime.ParseExact(StringDate.Trim,“dd-MM-yyyy”,system.Globalization.CultureInfo.InvariantCulture)

please help me out on this.

You should get first day of the previous month by assignig the following : DateTime.Now.AddMonths(-1).ToString(“01.MM.yyyy”)