I will try to explain my problem as clear as i can, my English not perfect, hope u can understand me. I have database contains some data, i load the data via VB.net in datagridview, everything ok so far. I have a column contains time records, for example "8:15 AM", the type of this column in sql server is (char(8)) , what I want, when i load the data in datagridview, any cell is empty will be in blue, and any cell that contains time data will be compared with another time i put, for example i want to compare the time in cell with time ="8:30 AM" if the cell's time is after 8:30 AM the cell will be in red, if not after or equal will be no change! hope u can under stand me. thanks
Asked
Active
Viewed 288 times
0
-
The answer to everything is [42](http://en.wikipedia.org/wiki/Phrases_from_The_Hitchhiker%27s_Guide_to_the_Galaxy), *not* `string`. Store datetime as `datetime`, date as `date` and time as (...wait for it!) **[time](https://msdn.microsoft.com/en-us/library/bb677243.aspx)**. Then, and only then, you'll be able to compare [time](https://msdn.microsoft.com/en-us/library/system.timespan%28v=vs.110%29.aspx). – Bjørn-Roger Kringsjå Feb 01 '15 at 13:50
-
the problem that i only can read the data from SQL server i am not able to change the data type, so is there any way to change the valuetype of the cell to time and then compare, i've tried many methods nothing works, i've changed the cell value and worked, but i cant compare, or i didn't know how to compare! – Osama Gadour Feb 01 '15 at 14:11
-
You can parse the string value to date and then get the time part: `Dim time As TimeSpan = Date.ParseExact("8:30 AM", "h:mm tt", CultureInfo.InvariantCulture).TimeOfDay` – Bjørn-Roger Kringsjå Feb 01 '15 at 14:20