Change what you get back from the
SELECT
to be the
DATETIME
value that is actually stored in the DB. Then get the
TimeOfDay
part and
use that everywhere else!
Try something like:
DateTime current_time = DateTime.Now;
TimeSpan End_time=current_time.TimeOfDay;
TimeSpan start_time = End_time.SubtractHours(-2);
DataTable dchild= new DataTable();
string query = "SELECT date_created FROM table";
adap_child = new MySqlDataAdapter(query, strconnection);
adap_child.Fill(dchild);
foreach (DataRow items in dchild.Rows)
{
TimeSpan time_to_be_compared = ((DateTime)items["date_created"]).TimeOfDay;
if (start_time <= time_to_be_compared && time_to_be_compared <= End_time)
{
}
else
{
}
}