if (DateTime.Compare(Session["opens"], Session["resdate"]) > 0)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

if (DateTime.Compare(Session["opens"], Session["resdate"]) > 0) produces
three errors. I need to know how to do DateTime comparison on a web page in
postback.
 
NCZIMM,

What are the errors that you are getting? I'm assuming that you are
getting an error with the fact that the Session collection returns objects
and not DateTime, which means that you will have to cast:

// Compare the datetimes.
if (DateTime.Compare((DateTime) Session["opens"], (DateTime)
Session["resdate"]) > 0)

Hope this helps.
 
Thanks, that got me past the build problem but when I run the app I get the
message "the specific cast is not valid". Line 173 is red.


Line 171: Session["resmonth"]=Calendar1.SelectedDate.Month;
Line 172:
Line
173: if(DateTime.Compare((DateTime)Session["opens"],(DateTime)Session["resdate"]) > 0)
Line 174: this.messagebox.Text="Reservations not available prior to
"+Session["opens"];
Line 175: if (DateTime.Compare((DateTime)Session["closes"],
(DateTime)Session["resdate"]) > 0)
 
how about this
If DateTime.Now = CType(Session("date"),Date) Then

careful with that vb code, it's not my strong point

--
Regards,
Alvin Bruney

Coming this month
The Microsoft Office Web Components Black Book with .NET
http://tinyurl.com/27cok
NCZIMM said:
Thanks, that got me past the build problem but when I run the app I get
the
message "the specific cast is not valid". Line 173 is red.


Line 171: Session["resmonth"]=Calendar1.SelectedDate.Month;
Line 172:
Line
173:
if(DateTime.Compare((DateTime)Session["opens"],(DateTime)Session["resdate"])
Line 174: this.messagebox.Text="Reservations not available prior to
"+Session["opens"];
Line 175: if (DateTime.Compare((DateTime)Session["closes"],
(DateTime)Session["resdate"]) > 0)




NCZIMM said:
if (DateTime.Compare(Session["opens"], Session["resdate"]) > 0) produces
three errors. I need to know how to do DateTime comparison on a web page
in
postback.
 
Back
Top