subtracting two dates to get number of days between

B

Brian Henry

How would i take two dates startdate and enddate and subtract startdate from
enddate to figure the number of days between the two? thanks
 
B

Brian Henry

neverminde :)

If DateDiff(DateInterval.Day, dbReader("sectionedited"), Now.Date) <= 30
Then
 
T

Tom Shelton

["Followup-To:" header set to microsoft.public.dotnet.languages.vb.]
How would i take two dates startdate and enddate and subtract startdate from
enddate to figure the number of days between the two? thanks

Dim Difference As TimeSpan = enddate.Subtract(startdate)
Console.WriteLine(Difference.Days)
 
B

Brian W

Not sure what language you want, but the VB isn't much differen that this C#

DateTime d1, d2; // Make sure you assign these first

TimeSpan ts = d1-d2;

int days = ts.Days;

HTH
Brian W
 
C

Chris Jackson

System.DateTime includes a Subtract method, which will do exactly this. In
C#, you can also use the - operator.
 
B

Brian Henry

when i do this

Dim diffNUmb As Integer = DateDiff(DateInterval.day,
dbReader.GetDateTime(dbReader.GetOrdinal("sectionedited")), Now())



the sectionedited attribute of the table in the dbreader being a datetime
with a date/time of #10/19/2003 12:00:00 AM# in it and i run it, every time
it will return 0 as the diffrence in days even though i change the month and
day in the fixed date... why would it do this? thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top