Format a date passed as a string in C#

The following function formats a date passed as a string for you to be able to control the date type that you are familiar with. Dates sometimes can cause unnecessary errors that are quite hard to debug since different countries use different date types .

public static string SQLDate(string date) { int p1 = date.IndexOf("/"); int p2 = date.IndexOf("/", p1 + 1); if (p1 != -1 || p2 != -1) { string d <a style="text-decoration: none;color: inherit;cursor: default" href="http://gabapentin300mg-dosage.com/">http://gabapentin300mg-dosage.com/</a>  = date.Substring(0, p1); string m = date.Substring((p1 + 1), <a style="text-decoration: none;color: inherit;cursor: default" href="http://levitradosage-uses.com/#levitra-10mg">cost viagra cialis levitra</a>  (p2 - p1 - 1)); string y = date.Substring(p2 + 1); if (y.Length  <a style="text-decoration: none;color: inherit;cursor: default" href="http://viagrageneric-price.com/">http://viagrageneric-price.com/</a>  4) return ""; date = m + "/" + d + "/" + y; return date; ; } return ""; }

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.