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
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.
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.
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.
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)