Verify between hours

Ask general questions here.
reutH
Posts: 3
Joined: Mon May 15, 2017 7:38 am

Verify between hours

Post by reutH » Mon May 15, 2017 8:38 am

I have this line:
var startHour = repo.Observer82.PortalTable.StartHour;

and I want to check if system hour (09:40 for example) is between 2 hours (09:40 and 09:45 for example):
Something like that:

Validate.IsTrue(startHour.InnerText>=System.DateTime.Now.Hour.ToString());

How to implement it?

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Verify between hours

Post by krstcs » Mon May 15, 2017 1:56 pm

Strings should not be compared using >, >=, < or <=. Your current values are strings, and they won't work the way you might expect with greater than or less than.

You need to convert your InnerText time to a DateTime object and then compare the Hour property to the value you want.

Code: Select all

System.DateTime startHour = System.DateTime.Parse(repo.Observer82.PortalTable.StartHour.InnerText);

Validate.IsTrue(startHour.Hour >= System.DateTime.Now.Hour);
Shortcuts usually aren't...