How to check if a certain string "yyyyMMdd" is within the last 10 days?

Hello,

I need to check if a certain string that contains a date “yyyyMMdd” is within the last 10 days.

For instance:
-> “this is the example 20190713 of the string”

I need to check whether 20190713 is a day within the last 10 days on today’s date (20190716)

Thanks!

@EngAnalyst,

Dim diff2 As String = (secondDate - firstDate).TotalDays.ToString()

This will give you the number of days between those two.So you can further proceed if it is less than 10

2 Likes

you can parse the string into a date using
Assign CertainDate = Date.ParseExact(StringDate,“yyyyMMdd”,system.Globalization.DateTimeFormatInfo.InvariantInfo) this will give you a datetime variable.

You can then check against datetime.now and compare if it is within
10 days using (CertainDate - DateTime.Now).TotalDays < 10;

2 Likes

Thank you both. Problem solved!

1 Like

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