473,394 Members | 1,696 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,394 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 18 '05 #1
6 10967
["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 18 '05 #2
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 18 '05 #3

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 18 '05 #4
((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 18 '05 #5
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 18 '05 #6
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 18 '05 #7

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

Similar topics

2
by: Tiernan | last post by:
Hi all I'm looking for a way to find the number of weekdays between 2 dates In my form I have three fields for a begin date (dd)(mm)(yyyy) and three for the end date (dd)(mm)(yyyy) Now these...
1
by: Jesse O | last post by:
I have two date fields, start_date and end_date. I'd like to subtract the two dates, and come up with a number (the number of difference between the two dates). What function is there to do...
7
by: Bambero | last post by:
Hello all Problem like in subject. There is no problem when I want to count days between two dates. Problem is when I want to count years becouse of leap years. For ex. between 2002-11-19...
5
by: SimonC | last post by:
Help needed for a Javascript beginner. As above in the subject... i need a javascript to run this, but not in the form of a web-page. I want to calculate it between 2 fields in a database that...
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
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...
10
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.