473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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
Nov 20 '05 #1
10 12955
["Followup-To:" header set to microsoft.public.dotnet.languages.vb.]
On 2003-11-19, Brian Henry <br******@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]
Nov 20 '05 #2
"Brian Henry" <br******@adelphia.net> schrieb
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
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
neverminde :)

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

"Brian Henry" <br******@adelphia.net> wrote in message
news:uE**************@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

Nov 20 '05 #4

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" <br******@adelphia.net> wrote in message
news:uE**************@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

Nov 20 '05 #5
((start.Ticks - end.Ticks) / TimeSpan.TicksPerHour) /24;

"Brian Henry" <br******@adelphia.net> wrote in message
news:uE**************@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

Nov 20 '05 #6
* "Brian Henry" <br******@adelphia.net> scripsit:
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())
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #7
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" <br******@adelphia.net> wrote in message
news:uE**************@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

Nov 20 '05 #8
when i do this

Dim diffNUmb As Integer = DateDiff(DateInterval.day,
dbReader.GetDateTime(dbReader.GetOrdinal("sectione dited")), 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" <br******@adelphia.net> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
neverminde :)

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

"Brian Henry" <br******@adelphia.net> wrote in message
news:uE**************@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


Nov 20 '05 #9
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
Nov 20 '05 #10
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
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bp*************@ID-208219.news.uni-berlin.de...
* "Brian Henry" <br******@adelphia.net> scripsit:
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())
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mojca | last post by:
What is formula that get days between two dates? Npr: 11.03.1998 – 1.7.2005 Thank you, Mojca
6
by: carl.barrett | last post by:
Hi, I have a continuous form based on a query ( I will also be creating a report based on the same query). There are 2 fields: Date Obtained and Date Of Expiry I want a further 3 columns...
11
by: Laery | last post by:
Hi, I'm currently adding a new module to an old borland C3.1 application (dos). And I need to calculate a date by subtracting the number of days from a given date. I know I could use an...
4
by: Russell | last post by:
I have an assignment that I have to complete. I have to write a windows app in C#. Here is the spec: 1/ Date Comparison Build a program that will find the number of days between two dates. You...
5
by: Juan | last post by:
Hi everyone, is there a function that calculates the exact amount of Years, Months, and Days between two days? TimeDiff is not good enough, since it calculates, for example: Date 1: Dec....
6
by: Brian Henry | last post by:
How would i take two dates startdate and enddate and subtract startdate from enddate to figure the number of days between the two? thanks
8
by: Ifollowhim | last post by:
I have a (installation) date in a table that I put in manually. It is the date we want to complete a job. In a form that uses data from that table I want to add a text box that is bound to the...
9
by: clintonb | last post by:
I'm looking for a way to calculate the number of days between two dates using standard C++ functions. Would it be as simple as just using the difftime() function and then dividing that result by...
9
by: ndeeley | last post by:
So, how do I count the number of days between two dates? I have set my variables to carry dates: <cfset dtFrom = #CreateODBCDate(dateFormat(form.Pump_FromDate, 'dd/mm/yyyy'))# /> <cfset dtTo =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.