Current Day date Comparison in IF Activity

Hello,

I am trying to generate an IF condition that compares a datetime variable from a previous activity with the current date. I do not want time to appear. My current condition reads: “variable < Date.Now” but I don’t believe this will inspire the bot to take the next step.

Thank you in advance!
Sara

1 Like

Hi Sara
Fine condition will work but with small correction buddy
Variable < DateTime.Now
or to be simpler
Variable < Now

But make sure that the variable mentioned is of type DateTime
Cheers @Sara_Car

2 Likes

@Palaniyappan As always, I appreciate your speed and accuracy!

One follow up question, if I may. I don’t want time to come through in the next step of my IF condition. I would like a Type Into and have this code:

Now.ToString(“mmddyyyy”) would the exclude the time? I have a write line on the initial variable and it is writing out time so I just want to check this.

Thank you so much!

@Sara_Car Now.ToString(“mmddyyyy”) Will exclude time and gives only month date and year

2 Likes

yes of course, it will exclude time stamp in it…and will give only the format that you have mentioned in the ToString argument
as you have mentioned here Now.ToString(“MMddyyyy”) it will give the output only in the format specified like 06112019
and one more thing MM is for month and mm is for minutes buddy…
Fine i would like to tell you something
this would surely help you buddy

Cheers @Sara_Car

@indra

Thank you for that confirmation! Cheers!

1 Like

@Palaniyappan Yes, I need to work on my coding language skills. Thank you for the link!

I will reference!

1 Like

Cheers
Keep going
@Sara_Car

Ok, I have a follow up question to all this. My IF condition is now working and I appreciate the support. However, now I have another stumbling block. I need to build in where the bot will type into an application the last date of the previous month. Since that will never be the current date, how best to achieve this?

1 Like

Hi @Sara_Car

we can get the last date of the previous month like this
datetime.DaysInMonth(now.Year,now.AddMonths(-1).Month)

1 Like

Hello @Palaniyappan,

Thank you once again. This only outputs the day (Meaning it only said 31 since May has 31 days). I would need the full date. I am working with the code to accomplish this.

Fine buddy
Use a assign activity like this
where in_date is variable of type string
in_date = now.AddMonths(-1).ToString(“MMyyyy”)+"/"+datetime.DaysInMonth(now.Year,now.AddMonths(-1).Month).ToString

Then we can convert the in_date like this to get the format we want, in writeline activity

Datetime.ParseExact(in_date,“MMyyyy/dd”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

Cheers @Sara_Car

@Palaniyappan You are amazing! This has worked! Thank you so much!

I always appreciate your time, accuracy, and speed!

1 Like

Cheers @Sara_Car
I would say it was a good question…Sara

So credit goes to you certainly… @Sara_Car

1 Like

@Palaniyappan No, I take no credit for this. You, sir are the one who has figured this out! Thank you very much!!

1 Like

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