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?
Verify between hours
Re: Verify between hours
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.
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...