Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys i want to also know how i can subtract 2 date and return only the number of days that have erapsed for example 3/22/2013-3/21/2013=1
Posted

1 solution

Quite simple :

C#
DateTime start = new DateTime(1, 1, 2013);
DateTime end = DateTime.Now;
TimeSpan ts = end - start;
int totalDays = ts.TotalDays;


Hope this helps.

[Edit] Sorry I didn't make attention to the tag. Here's in VB.NET :

VB
Dim startDate As DateTime = New DateTime(1, 1, 2013)
Dim endDate As DateTime = DateTime.Now
Dim ts As TimeSpan = endDate - startDate
Dim totalDays As Integer = ts.TotalDays
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900