Validation of a Date

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

Guest

Is there any way of using a validation control in c#.Net which finds out if
the date provided in a textbox is equal to or greater than the current date.
Does anyone know how to do this. Or does anyone know how to do this using c#
code.

Thanks for any help anyone is able to give me.
 
Is there any way of using a validation control in c#.Net which finds out if
the date provided in a textbox is equal to or greater than the current date.
Does anyone know how to do this. Or does anyone know how to do this using c#
code.

Thanks for any help anyone is able to give me.

Simply compare the ticks of the dates.

if (today.ticks >= Convert.ToDateTime(textBox.Text).Ticks)
 
Hi,

Is this a web or a win app?

if in win you can use Validating or LostFocus to make the check tht you
need. first convert the string to a datetime and then compare it with Today.

cheers,
 
I tried this but it doesn't seem to work have you any idea why

function DateCompatre(sender, args))
{
if(today.ticks >= Convert.ToDateTime(document.WebForm2.txtDate.Text).Ticks)
{
args.IsValid = true;
return;
}
args.IsValid = false;

}
 
Stephen said:
Is there any way of using a validation control in c#.Net which finds
out if the date provided in a textbox is equal to or greater than the
current date. Does anyone know how to do this. Or does anyone know
how to do this using c# code.

Thanks for any help anyone is able to give me.

If this is a WebApp, there is a CompareValidator. Set the Type to "Date",
the Operator to "GreaterThanEqual" and the ValueToCompare to
the current date.
Now if it was specified how the date format was handled, you could
almost use it (ddmmyyyy? mmddyyyy? yyyymmdd?)

Hans Kesting
 
Stephen,

Arne was refering to server side code (c#), not client side custom
validation (javascript).

Presumbly your saving details or updating somewhere (on click of an OK
button for example)... This would be the place to put Arne's if statement.

Daniel.
 
Back
Top