Guest User

Untitled

a guest
Jul 17th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. using System;
  2.  
  3. namespace TestInput
  4. {
  5. public class Tester
  6. {
  7. public static bool IsInteger(string p)
  8. {
  9. bool result = false;
  10. int i;
  11.  
  12. if (int.TryParse(p, out i))
  13. {
  14. result = true;
  15. }
  16.  
  17. return result;
  18. }
  19.  
  20. public static bool IsDate(string p)
  21. {
  22. bool result = false;
  23. DateTime dt;
  24.  
  25. if (DateTime.TryParse(p, out dt))
  26. {
  27. result = true;
  28. }
  29.  
  30. return result;
  31. }
  32.  
  33. public static int GetDifferenceInYears(DateTime startDate, DateTime endDate)
  34. {
  35. //Excel documentation says "COMPLETE calendar years in between dates"
  36. int years = endDate.Year - startDate.Year;
  37.  
  38. if (startDate.Month == endDate.Month &&// if the start month and the end month are the same
  39. endDate.Day < startDate.Day// AND the end day is less than the start day
  40. || endDate.Month < startDate.Month)// OR if the end month is less than the start month
  41. {
  42. years--;
  43. }
  44.  
  45. return years;
  46. }
  47.  
  48. public static bool IsDateAndLiesInTheFuture(string sDT)
  49. {
  50. bool result = false;
  51.  
  52. if (IsDate(sDT))
  53. {
  54. DateTime dtParsed = DateTime.Parse(sDT);
  55.  
  56. if (dtParsed > DateTime.Now)
  57. {
  58. result = true;
  59. }
  60. }
  61.  
  62. return result;
  63. }
  64.  
  65. public static bool IsDateAndLiesInThePast(string sDT)
  66. {
  67. bool result = false;
  68.  
  69. if (IsDate(sDT))
  70. {
  71. DateTime dtParsed = DateTime.Parse(sDT);
  72.  
  73. if (dtParsed < DateTime.Now)
  74. {
  75. result = true;
  76. }
  77. }
  78.  
  79. return result;
  80. }
  81.  
  82. public static int DaysTillNextBirthday(DateTime dateOfBirth)
  83. {
  84. //full days (whole, 24-hr periods) until next birthday...
  85. int result = 0;
  86. DateTime dtToday = DateTime.Now;
  87. DateTime dtNextBirthday = new DateTime(dtToday.Year, dateOfBirth.Month, dateOfBirth.Day);
  88. TimeSpan tsDifference = dtNextBirthday - dtToday;
  89.  
  90. if (tsDifference.Days < 0)
  91. {
  92. //already had birthday this year
  93. tsDifference = dtNextBirthday.AddYears(1) - dtToday;
  94. }
  95. result = tsDifference.Days;
  96. return result;
  97. }
  98. }
  99.  
  100. }
Add Comment
Please, Sign In to add comment