Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Difference between today and yesterday in C#

The difference is represented with milliseconds also.

  1. using System;
  2.  
  3. namespace forgetCode
  4. {
  5. class program
  6. {
  7. public static void Main()
  8. {
  9. // Difference between today and yesterday.
  10. DateTime yesterday = DateTime.Now.Subtract(TimeSpan.FromDays(1));
  11. DateTime now = DateTime.Now;
  12. TimeSpan diff = now.Subtract(yesterday);
  13. Console.WriteLine(diff);
  14. }
  15. }
  16. }


Output:
1.00:00:00.0010001