How to do the comparison between two dates

Dear all,

Good day.

I would like to identify whether the date is being backdated or not.

i have two variable , TodayDate & DeliverToDate, both is String variable.

DeliverTodate= row.item(0).ToString
TodayDate=DateTime.Now.ToString(“dd MMM yyyy”, System.Globalization.CultureInfo.InvariantCulture)

i use if condition under the following expression

if DeliverToDate<TodayDate
then will pop up error and stated it is backdated.

so i tested for below condition:-
DeliverToDate= 03 May 2021
Today Date= 26 Apr 2021

the expected outcome should be the workflow run successfully as it is not backdated.

But now it pops up error.

Kindly advise how to do so. Is it i will need to set both variable to be datetime variable?

but how to set the row item to be datetime variable?

Thank you

Hi,

I think it’s better.

For now, can you try the following expression?

Today>Datetime.Parse(row.item(0).ToString).Date

If this doesn’t work, need to use DateTime.ParseExtract method.

Regards,

@Yoichi thanks for your replied.
i tried but error pop up.

How can i use DateTime.ParseExtract method?

Hi,

If want to compare as DateTime type, DeliverToDate variable should be DateTime variable.
Can you try to modify it?

Regards,

yes modified. How about Today date variable? should i change to datetime variable as well?

Hi,

Today is property of DateTime (like Now property). We can use it directly (without define in advance).

So the condition will be the following.

Today > DeliverToDate

or

DateTime.Today > DeliverToDate

Regards,

Can you tell me how to set the format of the date?

05/03/2021 00:00:00
the date is 03 May 2021 in the excel, but the results show above.

How can i set it to be show as 03 May 2021 as well?

Hi,

How about the following?

DeliverToDate.ToString("dd MMM yyyy")

(The abbreviated name of the month.)

or

DeliverToDate.ToString("dd MMMM yyyy")

(The full name of the month.)

Regards,

yes it works now …thanks a lot

1 Like

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