Link to home
Start Free TrialLog in
Avatar of bmanmike39
bmanmike39

asked on

How do i subtract date1 from date2 and show the results

How do i subtract date1 from date2, and display the results.

Code i have:
DateTime date1 = DateTime.MinValue;
DateTime date2 = DateTime.MinValue;

DateTime.TryParse(x2, out date1);
DateTime.TryParse(x3, out date2);

Open in new window

Avatar of nap0leon
nap0leon

Your first two lines look funky... where are you getting "DateTime.MinValue"?

Anyway.... try this

Dim date1 As DateTime = Convert.ToDateTime(date one goes here)
Dim date2 As DateTime = Convert.ToDateTime(date two goes here)
Dim ts As TimeSpan = date2.Subtract(date1)

Response.Write(ts.Days)

Open in new window

what about this

DateTime dateDiff = DateTime.MinValue;
DateTime.TryParse(date2-date1, out dateDiff );
ASKER CERTIFIED SOLUTION
Avatar of nap0leon
nap0leon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial