Skip to content
Loading
  • Priyanka Jain
    0
    Try below code,
     
    1. (Convert.ToDateTime(y) - Convert.ToDateTime(x)).TotalDays  
     
    so it will look like below,
     
    1. class Program    
    2. {    
    3.     static void Main(string[] args)    
    4.     {    
    5.             Calculate("2019, 11. 08", "2018, 11, 09");    
    6.     }    
    7.     static string Calculate(string x, string y)    
    8.         {    
    9.             return (Convert.ToDateTime(y) - Convert.ToDateTime(x)).TotalDays.ToString();  
    10.         }    
    11. }    
     
    0
  • Amit Mohanty
    0
    Hey try this.
    1. DateTime compareTo = DateTime.Parse("01/01/2019");  
    2. DateTime now = DateTime.Parse("02/03/2019");  
    3. var dateSpan = DateTimeSpan.CompareDates(compareTo, now);  
    4. Console.WriteLine("Date diffrence between dt:" + compareTo.ToString("dd-MMM-yyyy") + " and dt:" + now.ToString("dd-MMM-yyyy"));  
    5. Console.WriteLine("Years: " + dateSpan.Years);  
    6. Console.WriteLine("Months: " + dateSpan.Months);  
    7. Console.WriteLine("Days: " + dateSpan.Days);  
    8. Console.WriteLine("Hours: " + dateSpan.Hours);  
    9. Console.WriteLine("Minutes: " + dateSpan.Minutes);  
    10. Console.WriteLine("Seconds: " + dateSpan.Seconds);  
    11. Console.WriteLine("Milliseconds: " + dateSpan.Milliseconds); 
    0
  • Mageshwaran R
    0
    Hi,
    Try this Code:
    1. (Y - X).TotalDays  
     
    0