Subtracting Dates in C# and SQL

I know this is really basic stuff but I have seen too many examples of someone trying to implement their own date class to do something simple like subtract one day from today’s date.  I also remember the day (long ago) someone showed me using negative numbers worked in the dateadd function of sql server.  So in case you have not found these functions yet, here are some samples.


This gives you a DateTime object with yesterday’s date.  (Note it will be yesterday at the current time)


Gives this result:

I think these are good examples of why you cannot forget the basics of math when you are working on a giant calculator. 

Hope this helps.