How to get previous date?

Getting previous date based on a format .

Date format sample : 210315 , that is YYMMDD. I want to check if date is a previous date

Current solution :>

sample_date.ToString.Trim.Split("-"c)(1).ToString < datetime.now.ToString(“yyMMdd”).ToString

But this will include date that are 2 days ago , I only want previous day date

Input : 210314 - True because today is 15 and previous day is 14
Input: 210313 - False since morethan 2 days already had passed this is not last day or previous day.

Any idea ? thanks.

u can use like this

sample_date.ToString.Equals(datetime.now.AddDays(-1).ToString(“yyMMdd”))

Regards,

Nived N

Happy Automation

2 Likes

As @NIVED_NAMBIAR has already indicated.

I have here a screenshot as a test :wink:

2 Likes

As an alternate you can try this too @AhmedKutraphali …shorter version of what @NIVED_NAMBIAR provided…

sample_date.ToString.Equals(Now.AddDays(-1).ToString(“yyMMdd”))

1 Like

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