subtracting two dates to get number of days between

  • Thread starter Thread starter Brian Henry
  • Start date Start date
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
 
neverminde :)

If DateDiff(DateInterval.Day, dbReader("sectionedited"), Now.Date) <= 30
Then
 
["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)
 
Brian Henry said:
How would i take two dates startdate and enddate and subtract
startdate from enddate to figure the number of days between the two?
thanks

I think the question is not specific to asp.net.


To get the difference:

Dim Diff As Timespan

diff = enddate.subtract(startdate)
msgbox diff.days
 
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 said:
How would i take two dates startdate and enddate and subtract startdate from
enddate to figure the number of days between the two? thanks

\\\
MsgBox(d2.Subtract(d1).Days.ToString())
///
 
System.DateTime includes a Subtract method, which will do exactly this. In
C#, you can also use the - operator.
 
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 this routine deducts the year value in a
datetimepicker from the year value on the system clock
I'm sure it could be easily amended by switching it with
your controls and using the day property instead of the
year.

Dim intYear As Integer
intYear = System.DateTime.Now.Year
intYear = System.DateTime.Now.Year.ToString -
dtpDOB.Value.Year.ToString
txtAge.Text = intYear


Regards Steve
 
Hello, when i did it like you suggested I got an error saying days was not a
member of subtract, it would let me do .day though... would this change
anything or will i still get the number of days between the date? (sorry im
not at my dev system right now to check) thanks
 
Back
Top