473,387 Members | 2,436 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,387 software developers and data experts.

date calculations

I am creating a program that involves having to find the difference between
two dates and converting it to a number to be used for calculations. The
problem is that the way it is setup, VB is not doing anything with the dates
that I have selected. I hope that someone here can help me figure out why it
is not working what I have to do to make it work.

This the code I have for the date calculations.

txtNumberOfDays.text = Val(dateTimeCheckout.Value.Date.ToString()) -
Val(dateTimeArrival.Value.Date.ToString)
Apr 26 '06 #1
8 2092
try this instead:

txtNumberOfDays.text =
datediff(days,dateTimeCheckout,dateTimeArrival).to string
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Apr 26 '06 #2
So, if I use EndDate.Subtract(StartDate), then it would look like this:

txtNumberOfDays = EndDate.Subtract(StartDate) ? Would that return a whole
number value like 3 days or 5 days?

"Spam Catcher" <sp**********@rogers.com> wrote in message
news:Xn*********************************@127.0.0.1 ...
"Charlie Brookhart" <ch****************@hotmail.com> wrote in
news:Js******************************@adelphia.com :
I am creating a program that involves having to find the difference
between two dates and converting it to a number to be used for
calculations. The problem is that the way it is setup, VB is not doing
anything with the dates that I have selected. I hope that someone here
can help me figure out why it is not working what I have to do to make
it work.

This the code I have for the date calculations.

You can also do:
EndDate.Substract(StartDate)

It'll return a TimeSpan object which has a variety of caluations (from
total days, total minutes, etc).

Apr 26 '06 #3
This method does not work because dateddiff and days are not declared.

txtNumberOfDays.text =
datediff(days,dateTimeCheckout,dateTimeArrival).to string
_________________________________________

This method does not work because EndDate and StartDate are not declared.

EndDate.Subtract(StartDate)
"Charlie Brookhart" <ch****************@hotmail.com> wrote in message
news:h6********************@adelphia.com...
So, if I use EndDate.Subtract(StartDate), then it would look like this:

txtNumberOfDays = EndDate.Subtract(StartDate) ? Would that return a whole
number value like 3 days or 5 days?

"Spam Catcher" <sp**********@rogers.com> wrote in message
news:Xn*********************************@127.0.0.1 ...
"Charlie Brookhart" <ch****************@hotmail.com> wrote in
news:Js******************************@adelphia.com :
I am creating a program that involves having to find the difference
between two dates and converting it to a number to be used for
calculations. The problem is that the way it is setup, VB is not doing
anything with the dates that I have selected. I hope that someone here
can help me figure out why it is not working what I have to do to make
it work.

This the code I have for the date calculations.

You can also do:
EndDate.Substract(StartDate)

It'll return a TimeSpan object which has a variety of caluations (from
total days, total minutes, etc).


Apr 26 '06 #4
Charlie,

There are in VB endless methods to handles dates.
But no methods to calculate with strings as you do.

Your instruction is in fact like this.
txtNumberOfDays.text = Val("Apples" - "Pears")

You can look at the datediff method, but better to the timespan methods.

Be aware that you are comparing with this exact complete days is less than a
million, so you have to decide yourself if a day plus some milliseconds is
one day or two.

http://msdn.microsoft.com/library/de...classtopic.asp

http://msdn.microsoft.com/library/de...sdaystopic.asp

I hope this helps,

Cor
Apr 26 '06 #5
Charlie Brookhart wrote:
I am creating a program that involves having to find the difference between
two dates and converting it to a number to be used for calculations. The
problem is that the way it is setup, VB is not doing anything with the dates
that I have selected. I hope that someone here can help me figure out why it
is not working what I have to do to make it work.

This the code I have for the date calculations.

txtNumberOfDays.text = Val(dateTimeCheckout.Value.Date.ToString()) -
Val(dateTimeArrival.Value.Date.ToString)


If it's not doing anything with the dates, your code is simply not
executed at all.

It has do be doing something, but I imagine nothing useful. You
shouldn't convert the dates to strings and back to numbers, as the
string representation of a date can not be interpreted as a single number.

You should use the methods of the DateTime class for comparing the
dates. Use the Subtract method and you will get a TimeSpan object, from
which you can get the difference between the dates most any way you
like. For an example:

txtNumberOfDays.text =
dateTimeCheckout.Value.Date.Subtract(dateTimeArriv al.Value.Date).TotalDays.ToString()
Apr 26 '06 #6
Try this:

Dim ts As TimeSpan

ts = EndDate.Subtract(StartDate)

txtNumberOfDays.Text = ts.Days

There are other properties of the TimeSpan object as well

Apr 26 '06 #7
Goran:

Thanks for your suggestion. I will give it a try.

Cor:

You say that my instructions are the equivalent of txtNumberOfDays.text =
Val("Apples" - "Pears"). What I don't understand is why doesn't VB see the
instructions I have as a value that I am trying to get, especially when I
start out using Val and then more specifically indicate that I want to get a
date value and subtract that value from another date value?

"Göran Andersson" <gu***@guffa.com> wrote in message
news:e7**************@TK2MSFTNGP05.phx.gbl...
Charlie Brookhart wrote:
I am creating a program that involves having to find the difference between two dates and converting it to a number to be used for calculations. The
problem is that the way it is setup, VB is not doing anything with the dates that I have selected. I hope that someone here can help me figure out why it is not working what I have to do to make it work.

This the code I have for the date calculations.

txtNumberOfDays.text = Val(dateTimeCheckout.Value.Date.ToString()) -
Val(dateTimeArrival.Value.Date.ToString)


If it's not doing anything with the dates, your code is simply not
executed at all.

It has do be doing something, but I imagine nothing useful. You
shouldn't convert the dates to strings and back to numbers, as the
string representation of a date can not be interpreted as a single number.

You should use the methods of the DateTime class for comparing the
dates. Use the Subtract method and you will get a TimeSpan object, from
which you can get the difference between the dates most any way you
like. For an example:

txtNumberOfDays.text =

dateTimeCheckout.Value.Date.Subtract(dateTimeArriv al.Value.Date).TotalDays.T
oString()
Apr 26 '06 #8
Carlie,

The Val method is rarely used.
It returns from a string an undefined value.

ToString is a method that is in any object. And everyhing in VBNet is an
object.

If it is overriden it can return a string of numbers. However from which the
value says not much. .

If you want to calculate with dates, than you have almost forever to use
dates in net. Even when you say
A = Cdate("01-01-2000")-Cdate("12-12-1999") you are calculating with dates.

The basic of your solution by the way is in the message from Chris Dunaway,

I hope this helps,

Cor

"Charlie Brookhart" <ch****************@hotmail.com> schreef in bericht
news:Ba******************************@adelphia.com ...
Goran:

Thanks for your suggestion. I will give it a try.

Cor:

You say that my instructions are the equivalent of txtNumberOfDays.text =
Val("Apples" - "Pears"). What I don't understand is why doesn't VB see the
instructions I have as a value that I am trying to get, especially when I
start out using Val and then more specifically indicate that I want to get
a
date value and subtract that value from another date value?

"Göran Andersson" <gu***@guffa.com> wrote in message
news:e7**************@TK2MSFTNGP05.phx.gbl...
Charlie Brookhart wrote:
> I am creating a program that involves having to find the difference between > two dates and converting it to a number to be used for calculations.
> The
> problem is that the way it is setup, VB is not doing anything with the dates > that I have selected. I hope that someone here can help me figure out why it > is not working what I have to do to make it work.
>
> This the code I have for the date calculations.
>
> txtNumberOfDays.text = Val(dateTimeCheckout.Value.Date.ToString()) -
> Val(dateTimeArrival.Value.Date.ToString)
>
>


If it's not doing anything with the dates, your code is simply not
executed at all.

It has do be doing something, but I imagine nothing useful. You
shouldn't convert the dates to strings and back to numbers, as the
string representation of a date can not be interpreted as a single
number.

You should use the methods of the DateTime class for comparing the
dates. Use the Subtract method and you will get a TimeSpan object, from
which you can get the difference between the dates most any way you
like. For an example:

txtNumberOfDays.text =

dateTimeCheckout.Value.Date.Subtract(dateTimeArriv al.Value.Date).TotalDays.T
oString()

Apr 26 '06 #9

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

Similar topics

1
by: Marc | last post by:
I've got a PHP script that's using fopen to connect to a remote web server and pick up data. I've run into a problem in calculating elapsed time. The remote web server outputs a time and I'd...
13
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and...
2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
11
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m...
2
by: Joe Jax | last post by:
I have some date calculations that add a time span to a date. The problem is, when I add a time span that is a whole number of days to a date, the result can be +/- 1 hour due to daylight savings....
1
by: bluerocket | last post by:
I have searched this group, and am not finding the answer I am looking for -- hope you can help. I have a front-end MS Access database hooked via a MyODBC link to a MySQL database. A modified...
5
by: Simon Dean | last post by:
Probably being a little thick here, but when you subtract one date away from another, how do you convert the resultant value into a number of days... I guess I could easily / 60 / 60 / 24... but...
3
by: Glencannon4424 via AccessMonster.com | last post by:
Hello, I have what I believe amounts to a Date Serial issue. I have the following columns in my table: Hire-Date Hire-Year WTD-RATE Wks-in-Yr
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.