I'm trying to make a delivery tab which will display all Purchase Order that haven't arrived yet. How do I compare a PODate Datetime field in the database to the DateTime.Now
I'm trying to use this code
DateTime poDate = DateTime.Parse(PODate.Text)
if ((poDate < DateTime.Now))
Panel1.Visible = "true";
Can it be done using select query, that will allow me to select all those Purchase Order that are late from the database
答案 0 :(得分:1)
Try to parse the variable via DateTime.Parse()
method,
DateTime poDate = DateTime.Parse(PODate.Text)
if ((poDate < DateTime.Now))
Panel1.Visible = "true";
or use Convert.ToDateTime()
method.
PODate = PODate.Text
if ((Convert.ToDateTime(PODate) < DateTime.Now))
Panel1.Visible = "true";
But please use google next time.
答案 1 :(得分:1)
Convert convert PODate.Text
to a DateTime
DateTime PODate = DateTime.ParseExact(PODate.Text, "your Date format", CultureInfo.InvariantCulture);
if ((poDate < DateTime.Now))
Panel1.Visible = "true";
Edit
In select
Query where @poDate
as InputParameter
select *
from Test_Table
where
@poDate < GETDATE()