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) 8 1981
try this instead:
txtNumberOfDays.text =
datediff(days,dateTimeCheckout,dateTimeArrival).to string
--
Sent via .NET Newsgroups http://www.dotnetnewsgroups.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).
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).
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
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()
Try this:
Dim ts As TimeSpan
ts = EndDate.Subtract(StartDate)
txtNumberOfDays.Text = ts.Days
There are other properties of the TimeSpan object as well
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()
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()
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
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 required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
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 synthesis of my design into a bitstream, not the C++...
|
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 starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
| |