How to Compare Date and Time

If you want to compare the Date & Time with Current time while trying to get the record which was opened in the past 24 hours and get the difference is Hrs, you need to do the following:

Convert the 2 dates of each string row to date time format.

Let ‘date1’ & ‘date2’ be the ‘DateTime’ variables for each row activity,

Date1 =Datetime.ParseExact(row("Date and Time").ToString.Trim(),"MM/dd/yyyy


Date2=Datetime.ParseExact(row("Updated date and Time").ToString().Trim(),"MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture)

Create a variable with ‘Timespan’ type. Let it be ‘TimeDiff’.

Assign TimeDiff=date2- date1

You can get the time difference in days, hours, minutes, seconds… by using TimeDiff.TotalDays, TimeDiff.TotalHours etc.