Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace TestInput
- {
- public class Tester
- {
- public static bool IsInteger(string p)
- {
- bool result = false;
- int i;
- if (int.TryParse(p, out i))
- {
- result = true;
- }
- return result;
- }
- public static bool IsDate(string p)
- {
- bool result = false;
- DateTime dt;
- if (DateTime.TryParse(p, out dt))
- {
- result = true;
- }
- return result;
- }
- public static int GetDifferenceInYears(DateTime startDate, DateTime endDate)
- {
- //Excel documentation says "COMPLETE calendar years in between dates"
- int years = endDate.Year - startDate.Year;
- if (startDate.Month == endDate.Month &&// if the start month and the end month are the same
- endDate.Day < startDate.Day// AND the end day is less than the start day
- || endDate.Month < startDate.Month)// OR if the end month is less than the start month
- {
- years--;
- }
- return years;
- }
- public static bool IsDateAndLiesInTheFuture(string sDT)
- {
- bool result = false;
- if (IsDate(sDT))
- {
- DateTime dtParsed = DateTime.Parse(sDT);
- if (dtParsed > DateTime.Now)
- {
- result = true;
- }
- }
- return result;
- }
- public static bool IsDateAndLiesInThePast(string sDT)
- {
- bool result = false;
- if (IsDate(sDT))
- {
- DateTime dtParsed = DateTime.Parse(sDT);
- if (dtParsed < DateTime.Now)
- {
- result = true;
- }
- }
- return result;
- }
- public static int DaysTillNextBirthday(DateTime dateOfBirth)
- {
- //full days (whole, 24-hr periods) until next birthday...
- int result = 0;
- DateTime dtToday = DateTime.Now;
- DateTime dtNextBirthday = new DateTime(dtToday.Year, dateOfBirth.Month, dateOfBirth.Day);
- TimeSpan tsDifference = dtNextBirthday - dtToday;
- if (tsDifference.Days < 0)
- {
- //already had birthday this year
- tsDifference = dtNextBirthday.AddYears(1) - dtToday;
- }
- result = tsDifference.Days;
- return result;
- }
- }
- }
Add Comment
Please, Sign In to add comment