elena1234

Date Modifier- calculate days betwen two dates

Feb 6th, 2021 (edited)
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace DateModifier
  5. {
  6.     class DateModifier
  7.     {
  8.         public DateModifier()
  9.         {
  10.             this.ListWithAllDays = new List<DateTime>();
  11.         }
  12.  
  13.         public DateTime StartDate { get; set; }
  14.         public DateTime EndDate { get; set; }
  15.         public List<DateTime> ListWithAllDays { get; set; }
  16.  
  17.         public List<DateTime> ReturnDaysBetwenTwoDates(string startDate, string endDate)
  18.         {
  19.             this.StartDate = DateTime.Parse(startDate);
  20.             this.EndDate = DateTime.Parse(endDate);
  21.             if(this.StartDate < this.EndDate)
  22.             {
  23.                 for (DateTime date = this.StartDate; date < this.EndDate; date = date.AddDays(1))
  24.                 {
  25.                     this.ListWithAllDays.Add(date);
  26.                 }
  27.             }
  28.  
  29.             else
  30.             {
  31.                 for (DateTime date = this.EndDate; date < this.StartDate; date = date.AddDays(1))
  32.                 {
  33.                     this.ListWithAllDays.Add(date);
  34.                 }
  35.             }
  36.          
  37.             return this.ListWithAllDays;
  38.         }
  39.     }
  40. }
  41.  
Add Comment
Please, Sign In to add comment