How i can input begin date of the month and end of the month in Website

Hi i’m new using uipath and its been great experience . Im wondering if the uipath can autodetect the date from the system and input the begin date and end date per month.

For example
Now is 4 January 2018
so i need to input 01-01-2018 and 31-01-2018 in text column
date

Sorry for my poor english and i hope its enough to understand my question

Thanks
Himawan

@delf, Use the following in Assign Activity

dateTime beginDate = new DateTime(now.Year,now.Month,1)
dateTime lastDate = beginDate.AddMonths(1).AddDays(-1)

Your expected output :

string startDate = beginDate.ToString(“dd-MM-yyyy”)
string endDate = lastDate.ToString(“dd-MM-yyyy”)

Note: Use this startDate and endDate Variable in you rinput activity (TypeInto)

Regards,
Dominic :slight_smile:

4 Likes

instead use this

Date.ParseExact(now.AddMonths(1).ToString(“MM/01/yyyy”),“MM/dd/yyyy”,nothing).AddDays(-1).ToString(“dd-MM-yyyy”)

1 Like

Can you elaborate why this is better?

if today date = 4th Jan 2018 then
beginDate.AddMonths(1).AddDays(-1) will give 3rd Feb 2018 which is wrong. Cause it is subtracting only one day where day can be any day of the month 1 to 31

@AkshaySandhu, Thanks for the attention !

And it works fine.

Adding the following link for your reference, Add Months Remarks.

Regards,
Dominic :slight_smile:

Hello @599712

Example given in ref link is correct where date is static with date 12/31/2015, we are adding only months.
by default while adding months if date is not in the range of resulted month then date is keep on reducing by 1 (please correct me if I am wrong) until it is in range.

@AkshaySandhu, Sorry if it is wrongly mapped. Refer the explanation given in Remarks Section in the above link.

The AddMonths method calculates the resulting month and year, taking into account leap years and the number of days in a month, then adjusts the day part of the resulting DateTime object

Regards,
Dominic :slight_smile:

Hello @599712 my bad I didnt saw that your are using beginDate as date to get the last day of the current month. Your answer is correct :handshake:.
Sorry for misunderstanding

2 Likes

@AkshaySandhu,

Its okay dude !

Regards,
Dominic :slight_smile:

Thanks all for the reply… I will try later after i’m finished doing some tweak in my workbook.

Cheers

Himawan

Thanks all… already using this and worked…thank you