CoderSource.net
Search
Re: code for date validation
Started by dharan at 04-14-2006 2:12 AM. Topic has 1 replies.

Print Search « Previous Thread Next Thread »
   04-14-2006, 2:12 AM
dharan is not online. Last active: 6/21/2007 10:04:34 AM dharan

Top 10 Posts
Joined on 11-23-2005
Posts 7
code for date validation

hi everybody, i am new to c#.net.

 how to write validations for a date in c#.net applications that to in dd/mm/yy format.


   Report 
   04-14-2006, 10:27 AM
Yasir is not online. Last active: 11/16/2006 10:02:40 AM Yasir

Top 10 Posts
Joined on 03-15-2006
Posts 44
Re: code for date validation
Hi

you can use the following function to validate your date.

static bool ValidateDate(String date, String format)
{
try
{
System.Globalization.DateTimeFormatInfo dtfi = new
System.Globalization.DateTimeFormatInfo();
dtfi.ShortDatePattern = format;
DateTime dt = DateTime.ParseExact(date, "d", dtfi);
}
catch(Exception)
{
return false;
}
return true;
}

call this function like this

ValidateDate("12/25/06","MM/dd/yy");




   Report 
Codersource.Net » Programming » C# Programming » Re: code for date validation

MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Welcome to Codersource.Net Login | Register | Faq  

Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us