Thursday 8 July, 2010

C# ISDATE FUNCTION

Just a small simple method I wrote in C# that's similar to Visual Basic's IsDate() function.. Inputs string date, returns boolean true/false if string is a valid date or not.

  1. public bool IsDate(string sdate) {
  2. DateTime dt;
  3. bool isDate = true;
  4. try {
  5. dt = DateTime.Parse(sdate);
  6. }
  7. catch {
  8. isDate = false;
  9. }
  10. return isDate;
  11. }

2 comments:

  1. Dude, why did you use Hungarian notation? "sDate". Horrible if people are going to copy and use this code... you are encouraging horrible coding practices here. Just put "date" as the param name.

    ReplyDelete
  2. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Same as your blog I found another one Sohman Epoxy
    . Actually, I was looking for the same information on the internet forhsc-7600
    and came across your blog. I am impressed by the information that you have on this blog. Thanks once more for designs.

    ReplyDelete