472,353 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Number of days between 2 dates...

I want to work out the difference (number of days) between 2 dates selected
using the date picker in vb.net and displaying this in textbox1 (which will
be un-editable to the user)

An MVP game me the following code, which looks acceptable to me in practice,
but appears to always through up 0 in textbox1??? Am I doing anything
blatantly wrong or is there anything else I need to do???

Dim d1, d2 As Date
Me.txtlength.Text = CStr(d2.Subtract(d1).Days)

Is this code correct or do I need something else?

Scott
Nov 21 '05 #1
6 17369
Scott,

You need to put some date values into the 2 date variables. For example:

Dim d1, d2 As Date

d1 = #2/20/2005#
d2 = Now

MsgBox(CStr(d2.Subtract(d1).Days))

Kerry Moorman

"Scott" wrote:
I want to work out the difference (number of days) between 2 dates selected
using the date picker in vb.net and displaying this in textbox1 (which will
be un-editable to the user)

An MVP game me the following code, which looks acceptable to me in practice,
but appears to always through up 0 in textbox1??? Am I doing anything
blatantly wrong or is there anything else I need to do???

Dim d1, d2 As Date
Me.txtlength.Text = CStr(d2.Subtract(d1).Days)

Is this code correct or do I need something else?

Scott

Nov 21 '05 #2
Scott,

I think it is correct although I would probably do this when you don't want
the days in elapsed hours/minutes/seconds.

CStr(d2.Date.Subtract(d1.Date).Days)

I hope this helps

Cor
Nov 21 '05 #3
Scott,
As Kerry suggests:
Dim d1, d2 As Date d1 = Me.DateTimePicker1.Value
d2 = Me.DateTimePicker2.Value Me.txtlength.Text = CStr(d2.Subtract(d1).Days)
Hope this helps
Jay

"Scott" <ho*******@virgin.net> wrote in message
news:mI****************@newsfe5-gui.ntli.net...I want to work out the difference (number of days) between 2 dates selected
using the date picker in vb.net and displaying this in textbox1 (which will
be un-editable to the user)

An MVP game me the following code, which looks acceptable to me in
practice, but appears to always through up 0 in textbox1??? Am I doing
anything blatantly wrong or is there anything else I need to do???

Dim d1, d2 As Date
Me.txtlength.Text = CStr(d2.Subtract(d1).Days)

Is this code correct or do I need something else?

Scott

Nov 21 '05 #4
yeah that's what I was after...

I didn't know how to do the Me.DateTimePicker1.Value as I couldn't find
anything in the help files about that... But that good!!!

Cheers

Scott

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:el****************@TK2MSFTNGP10.phx.gbl...
Scott,
As Kerry suggests:
Dim d1, d2 As Date

d1 = Me.DateTimePicker1.Value
d2 = Me.DateTimePicker2.Value
Me.txtlength.Text = CStr(d2.Subtract(d1).Days)


Hope this helps
Jay

"Scott" <ho*******@virgin.net> wrote in message
news:mI****************@newsfe5-gui.ntli.net...
I want to work out the difference (number of days) between 2 dates
selected using the date picker in vb.net and displaying this in textbox1
(which will be un-editable to the user)

An MVP game me the following code, which looks acceptable to me in
practice, but appears to always through up 0 in textbox1??? Am I doing
anything blatantly wrong or is there anything else I need to do???

Dim d1, d2 As Date
Me.txtlength.Text = CStr(d2.Subtract(d1).Days)

Is this code correct or do I need something else?

Scott


Nov 21 '05 #5
"Scott" <ho*******@virgin.net> schrieb:
I want to work out the difference (number of days) between 2 dates selected
using the date picker in vb.net and displaying this in textbox1 (which will
be un-editable to the user)

An MVP game me the following code, which looks acceptable to me in
practice, but appears to always through up 0 in textbox1??? Am I doing
anything blatantly wrong or is there anything else I need to do???

Dim d1, d2 As Date
Me.txtlength.Text = CStr(d2.Subtract(d1).Days)


You are never assigning a date to 'd1' and 'd2'. The code below will fill
'd1' and 'd2' with the dates selected in the datetimepicker controls:

\\\
Dim d1 As Date = DateTimePicker1.Value
Dim d2 As Date = DateTimePicker2.Value
Me.txtlength.Text = CStr(d2.Subtract(d1).Days)
///

Alternatively you can use this (shorter) code:

\\\
Me.txtlength.Text = _
CStr(DateTimePicker2.Value.Subtract(DateTimePicker 1.Value).Days)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
Scott wrote:
I want to work out the difference (number of days) between 2 dates selected
using the date picker in vb.net and displaying this in textbox1 (which will
be un-editable to the user)

An MVP game me the following code, which looks acceptable to me in practice,
but appears to always through up 0 in textbox1??? Am I doing anything
blatantly wrong or is there anything else I need to do???

Dim d1, d2 As Date
Me.txtlength.Text = CStr(d2.Subtract(d1).Days)

Is this code correct or do I need something else?

Scott

Just after your declarations, you'll need lines like the following:

d1 = datetimepicker1.Value
d2 = datetimepicker2.Value

....but replace "datetimepicker1" and "datetimepicker2" with the names of
your date time pickers
Nov 21 '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...
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...
3
by: jerry.ranch | last post by:
I have a need to convert simple dates (i.e. 02/14/2005) to a number, do some math, and convert back to a date. (in a simple query). The math...
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...
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
10
by: Scott Kilbourn | last post by:
Hi, Does anyone know how to accurately calculate the number of days that have elapsed since 01/01/0000? I'd appreciate any help anyone could...
29
by: james | last post by:
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old database file that...
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...
1
by: bharathreddy | last post by:
This article will explain how we can get the count of weekdays in between two dates. This will be usefull if we want to count the number of working...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.