Wednesday, March 28, 2012

subtracting two dates to get number of days between

How would i take two dates startdate and enddate and subtract startdate from
enddate to figure the number of days between the two? thanks["Followup-To:" header set to microsoft.public.dotnet.languages.vb.]
On 2003-11-19, Brian Henry <brianiup@.adelphia.net> wrote:
> 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)

--
Tom Shelton
[MVP - Visual Basic]
neverminde :)

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

"Brian Henry" <brianiup@.adelphia.net> wrote in message
news:uEyFv6trDHA.2360@.TK2MSFTNGP10.phx.gbl...
> How would i take two dates startdate and enddate and subtract startdate
from
> enddate to figure the number of days between the two? thanks
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

"Brian Henry" <brianiup@.adelphia.net> wrote in message
news:uEyFv6trDHA.2360@.TK2MSFTNGP10.phx.gbl...
> How would i take two dates startdate and enddate and subtract startdate
from
> enddate to figure the number of days between the two? thanks
((start.Ticks - end.Ticks) / TimeSpan.TicksPerHour) /24;

"Brian Henry" <brianiup@.adelphia.net> wrote in message
news:uEyFv6trDHA.2360@.TK2MSFTNGP10.phx.gbl...
> How would i take two dates startdate and enddate and subtract startdate
from
> enddate to figure the number of days between the two? thanks
System.DateTime includes a Subtract method, which will do exactly this. In
C#, you can also use the - operator.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Shell/UI
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Brian Henry" <brianiup@.adelphia.net> wrote in message
news:uEyFv6trDHA.2360@.TK2MSFTNGP10.phx.gbl...
> How would i take two dates startdate and enddate and subtract startdate
from
> enddate to figure the number of days between the two? thanks
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

"Brian Henry" <brianiup@.adelphia.net> wrote in message
news:%23Ko5QBurDHA.540@.tk2msftngp13.phx.gbl...
> neverminde :)
> If DateDiff(DateInterval.Day, dbReader("sectionedited"), Now.Date) <= 30
> Then
>
> "Brian Henry" <brianiup@.adelphia.net> wrote in message
> news:uEyFv6trDHA.2360@.TK2MSFTNGP10.phx.gbl...
> > How would i take two dates startdate and enddate and subtract startdate
> from
> > enddate to figure the number of days between the two? thanks

0 comments:

Post a Comment