I'm making a function that would cancel an order only if it's within 60 minutes, what I was suggested is to compare the datetime value of the order to the current datetime.
using (SqlConnection con = new SqlConnection(Helper.GetCon()))
{
con.Open();
string query = @"SELECT * from [Order] where orderid = @id";
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.AddWithValue("@id", id);
using (SqlDataReader data = cmd.ExecuteReader())
{
DataTable dt = new DataTable();
dt.Load(data);
foreach (DataRow dr in dt.Rows)
{
var supplier = new Supplier();
supplier.OrderDate = DateTime.Parse(dr["OrderDate"].ToString());
}
}
}
return View();
So far I've only taken the datetime from the database, I was wondering how you can get the current datetime and get the difference in let's say minutes or hours so that I can make a conditional statement to allow or not allow the cancellation of an order. I'm fairly new to this and any help would be appreciated! Thank you!