Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

subtracting from the current date

I have a date value and I need to subract it from the current date(DateTime.Now). Which is a timespan value so therefore this calculation is not working.

MyTime = a datetime value from my database.

I need to subract:

NewTime = DateTime.Now - MyTime;

I cannot seem to figure out how to get this to work!

any help would be great!

thanks Jordan





0
jrmcdona
Asked:
jrmcdona
  • 2
2 Solutions
 
AaronReamsCommented:
DateTime date2 = DateTime.Now;
DateTime date1 = MyTime;
TimeSpan diff1 = date2.Subtract(date1);
0
 
AaronReamsCommented:
Of course this should work too...

TimeSpan diff2 = date2 - date1;
0
 
Fahad MukhtarDistinguished EngineerCommented:
DateTime MyTime = DateTime.Parse("12/12/2003"); // this will be from database
DateTime NewTime = DateTime.Now.Add( -(DateTime.Now- MyTime));
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now