Home All Groups Group Topic Archive Search About

CompareValidator for dates > than today

Author
13 Jan 2006 10:07 PM
tshad
I am trying to check the date of my field to check if it is greater that
today, but I am getting an error.

I am using :

        <asp:CompareValidator runat="server"
         ControlToCompare="RequestedStartDate"
         Operator="GreaterThan"
         Display="Dynamic"
         ValueToCompare = DateTime.Today.ToShortDateString()
         Type="Date" text="<br>Invalid Start Date"/>

But it gives me an error:

   The value 'DateTime.Today()' of the ValueToCompare property of '' cannot
be converted to type 'Date'

I also tried DateTime.Today(), but got the same error.  How would I do this?

Thanks,

Tom

Author
13 Jan 2006 10:42 PM
tdavisjr
tshad wrote:
Show quote
> I am trying to check the date of my field to check if it is greater that
> today, but I am getting an error.
>
> I am using :
>
>         <asp:CompareValidator runat="server"
>          ControlToCompare="RequestedStartDate"
>          Operator="GreaterThan"
>          Display="Dynamic"
>          ValueToCompare = DateTime.Today.ToShortDateString()
>          Type="Date" text="<br>Invalid Start Date"/>
>
> But it gives me an error:
>
>    The value 'DateTime.Today()' of the ValueToCompare property of '' cannot
> be converted to type 'Date'
>
> I also tried DateTime.Today(), but got the same error.  How would I do this?
>
> Thanks,
>
> Tom

How about this:

ValueToCompare = '<%= DateTime.Today.ToShortString() %>'

put a semi-colon to the end of the ToShortString() if using C#.  See if
that works
Author
17 Jan 2006 12:16 PM
tshad
Show quote
"tdavisjr" <tdavi***@gmail.com> wrote in message
news:1137192122.282627.107820@z14g2000cwz.googlegroups.com...
>
> tshad wrote:
> > I am trying to check the date of my field to check if it is greater that
> > today, but I am getting an error.
> >
> > I am using :
> >
> >         <asp:CompareValidator runat="server"
> >          ControlToCompare="RequestedStartDate"
> >          Operator="GreaterThan"
> >          Display="Dynamic"
> >          ValueToCompare = DateTime.Today.ToShortDateString()
> >          Type="Date" text="<br>Invalid Start Date"/>
> >
> > But it gives me an error:
> >
> >    The value 'DateTime.Today()' of the ValueToCompare property of ''
cannot
> > be converted to type 'Date'
> >
> > I also tried DateTime.Today(), but got the same error.  How would I do
this?
> >
> > Thanks,
> >
> > Tom
>
> How about this:
>
> ValueToCompare = '<%= DateTime.Today.ToShortString() %>'
>
> put a semi-colon to the end of the ToShortString() if using C#.  See if
> that works
>
That was what I was looking for.

Thanks,

Tom

AddThis Social Bookmark Button