// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Globalization; namespace E { public class Program { public static bool IsValidDate(string s) { DateTime dt; if(DateTime.TryParseExact(s, "yyyy-MM-dd", new CultureInfo("en-US"), DateTimeStyles.None, out dt)) { if(dt > DateTime.Now.Date || dt < DateTime.Now.AddMonths(-3)) { return false; } else { return true; } } else { return false; } } public static void Main(string[] args) { Console.WriteLine(IsValidDate("2012-11-27")); Console.WriteLine(IsValidDate("2012-11-29")); Console.WriteLine(IsValidDate("2012-7-27")); Console.WriteLine(IsValidDate("2012-10-32")); Console.WriteLine(IsValidDate("12-11-27")); } } }