Link to home
Create AccountLog in
Avatar of Carla Romere
Carla RomereFlag for United States of America

asked on

Using the Date to Determine Object Visibility

I want to have a <div> control on my page that only displays up to a certain date. I tried this:

    protected void Page_Load(object sender, EventArgs e)
        if (System.DateTime.Now > "08-15-2011")
            earningscall.Visible = false;

But, that gives me this error:

CS0019: Operator '>' cannot be applied to operands of type 'System.DateTime' and 'string'

How can I use the current date to determine whether or not to display a control?
Avatar of BourbonKid
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of codingbeaver
First, convert string "08-15-2011" to DataTime type.

Then use DateTime.Compare to compare two dates.
Avatar of Carla Romere


Stupendous! Does exactly what I wanted.