This method validates that a date string is in the proper MM/DD/YYYY format. It splits the date string on the '/' character, converts each part to an integer, and attempts to create a DateTime object from the values. If successful, it returns true, otherwise it returns false.
This method validates that a date string is in the proper MM/DD/YYYY format. It splits the date string on the '/' character, converts each part to an integer, and attempts to create a DateTime object from the values. If successful, it returns true, otherwise it returns false.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1
/// <summary>
/// Determine if Date String is an actual date
/// Date format = MM/DD/YYYY /// </summary> /// <param name="date"></param> /// <returns></returns> private bool ValidateDate(string date ! try ! // for "S# alter to suit if splitting on $yp$en# comma# etc% string&' date(arts = date%Split()/)* // create ne+ date from t$e parts* if t$is does not fail // t$e met$od +ill return true and t$e date is valid Date,ime testDate = ne+ Date,ime(-onvert%,o.nt/0(date(arts&0'# -onvert%,o.nt/0(date(arts&1'# -onvert%,o.nt/0(date(arts&2'* return true* 3 catc$ ! // if a test date cannot be created# t$e // met$od +ill return false return false* 3 3
C# Is A Simple, Modern, General-Purpose, Object-Oriented Programming Language Developed by Microsoft. C# Programming Is Very Much Based On C and C++ Programming Languages