[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4388
  • Last Modified:

Date validation C# asp.net.

I need to be able to validate that a year put in to a text box is greater than the year 1900.  I have no idea of how to accomplish this.  Please help.
0
Pemberley1
Asked:
Pemberley1
  • 2
1 Solution
 
jj819430Commented:
TextBox T is the TextBox you have on the page.

DateTime EnteredDate = Convert.ToDateTime(T.Text);  // put in a try catch to make sure that it works.
if(EnteredDate.Year < 1900)
{
uh oh
}
else
{
ok
}
0
 
jj819430Commented:
<= instead of < if it cannot be 1900

you can also do it as
System.DateTime Acceptable = Convert.ToDateTime("1/1/1900");
if(Convert.ToDateTime(T.Text) > Acceptable)
{
ok
}
else
{
uh oh
}
0
 
Pemberley1Author Commented:
Thanks!!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now