How to find the middle date of the month?

Hello! Everyone,

I have 9 dates format dd/mm/yyy. I need to find the middle date of the each month in 9 dates.

Ex - Actual date: (12/04/2022) here I need to get the date (15/04/2022)

Date and month are dynamic. If month is having 31 days need to get the date of 15 or 16. If it is 30 days need to get 15.

Is it possible to get the date like this?

Regards,

@Palaniyappan
@Yoichi

Hi,

Can you try the following?

dtVar=DateTime.ParseExact("12/04/2022","dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture)

Then

New DateTime(dtVar.Year,dtVar.Month,DateTime.DaysInMonth(dtVar.Year,dtVar.Month)>>1).ToString("dd/MM/yyyy")

or

New DateTime(dtVar.Year,dtVar.Month,CInt(Math.Round(DateTime.DaysInMonth(dtVar.Year,dtVar.Month)/2))).ToString("dd/MM/yyyy")

Regards,

Hi! @Yoichi

Thanks for the quick reply. I encountered this error.

Regards,

Hi,

Is item variable datetime string such as β€œ12/04/2021”?
If so, can you create DateTime variable (let’s say dtVar) and use the following expression in Assign activity?

dtVar=DateTime.ParseExact(item,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture)

Then use this expression

New DateTime(dtVar.Year,dtVar.Month,DateTime.DaysInMonth(dtVar.Year,dtVar.Month)>>1).ToString("dd/MM/yyyy")

Regards,

Hi!

Yes, in item I have 9 different dates and months with the same format( dd/MM/yyyy).

As you mentioned i have taken one for each which is the type argument of datetime. and also i have created date time variable.

it is throwing an error

Error: Specified cast is not valid

Regards,

Hi,

Can you check your variable type? And also the following sample might help you.

Main.xaml (8.1 KB)

Regards,

1 Like

Thanks a lot @Yoichi

It’s working fine…

Regards,

1 Like

@Unknown_User ,

you can use following example also if you want

DateTime.Parse(now.year.ToString +β€œ/”+now.Month.ToString +β€œ/”+ (DateTime.DaysInMonth(now.Year,now.Month)/2).ToString)

1 Like

Hi @Yoichi and @SamanGuruge

I need to get the first date of next month.

since, we have got the middle of the month date right. need to get the next month 1 st date.

EX:- Date(15/04/2021) expected date (01/05/2021)

Do i need to create new thread or can i continue here?

Regards,

Hi,

Can you try the following expression?

dtVar=DateTime.ParseExact(item,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture)

Then

New DateTime(dtVar.Year,dtVar.Month,1).AddMonths(1).ToString("dd/MM/yyyy")

Regards,

1 Like

please create a new topic. Thanks

1 Like

Hi @Unknown_User

DateTime.Parse(now.Year.ToString +β€œ/”+(now.Month+1).ToString+β€œ/1”)

1 Like

@Unknown_User , @SamanGuruge
we focus to scope the different topics to only one case. So researchers can easier find the solutions when they are researching for their case

lets assume:
grafik
would produce:
grafik
an invalid date

we could handle like
grafik

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.