Compare Time string with DateTime

Hey! I have two strings, one will contain “-text- … 2PM …-text-” and the other “-text- … 10AM …-text-”.
I want my bot to check the current time, and if right now it’s 2pm or later I want to take the 2 pm string, but if right now it’s earlier than 2pm I want to keep the 10am string.
I just want to know how to compare the 2pm and 10am strings with Now.Date.

Thanks !

Hi, I don’t get it… How are you comparing the 2PM string?
This expression: cdate(Now.ToString(“hh ttt”)) is not doing anything

Hey sorry thats my mistake

Instead of hh ttt put 2 PM


We can extract time string (like 2PM or 10AM) from your original string as the following expression.

 s = System.Text.RegularExpressions.Regex.Match(text,"[12]?[0-9][AP]M").Value

Then we can compare it with now as the following expression.



Hello Jad,
In this video I do a lot of stuff with DateTime:

20:05 DateTime to string in multiple ways
23:00 AddDays get DayofWeek
25:40 Convert from String to DateTime
26:20 Compare DateTime

Cristian Negulescu