473,573 Members | 2,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(dateTimeChe ckout.Value.Dat e.ToString()) -
Val(dateTimeArr ival.Value.Date .ToString)
Apr 26 '06 #1
8 2106
try this instead:

txtNumberOfDays .text =
datediff(days,d ateTimeCheckout ,dateTimeArriva l).tostring
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Apr 26 '06 #2
So, if I use EndDate.Subtrac t(StartDate), then it would look like this:

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

"Spam Catcher" <sp**********@r ogers.com> wrote in message
news:Xn******** *************** **********@127. 0.0.1...
"Charlie Brookhart" <ch************ ****@hotmail.co m> wrote in
news:Js******** *************** *******@adelphi a.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.Substra ct(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,d ateTimeCheckout ,dateTimeArriva l).tostring
_______________ _______________ ___________

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

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

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

"Spam Catcher" <sp**********@r ogers.com> wrote in message
news:Xn******** *************** **********@127. 0.0.1...
"Charlie Brookhart" <ch************ ****@hotmail.co m> wrote in
news:Js******** *************** *******@adelphi a.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.Substra ct(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(dateTimeChe ckout.Value.Dat e.ToString()) -
Val(dateTimeArr ival.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 =
dateTimeCheckou t.Value.Date.Su btract(dateTime Arrival.Value.D ate).TotalDays. ToString()
Apr 26 '06 #6
Try this:

Dim ts As TimeSpan

ts = EndDate.Subtrac t(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.co m> wrote in message
news:e7******** ******@TK2MSFTN GP05.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(dateTimeChe ckout.Value.Dat e.ToString()) -
Val(dateTimeArr ival.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 =

dateTimeCheckou t.Value.Date.Su btract(dateTime Arrival.Value.D ate).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.co m> schreef in bericht
news:Ba******** *************** *******@adelphi a.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.co m> wrote in message
news:e7******** ******@TK2MSFTN GP05.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(dateTimeChe ckout.Value.Dat e.ToString()) -
> Val(dateTimeArr ival.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 =

dateTimeCheckou t.Value.Date.Su btract(dateTime Arrival.Value.D ate).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
2023
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 like to calculate the difference between that time and the current time. The problem is that the time on the remote server isn't in sync with the...
13
9277
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 three dropdow boxes for hours, minutes, and AM/PM. All of these need to be considered together and converted to one Unix Timestamp and then inserted...
2
5205
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 appreciated. TIA
30
3654
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 seems unnecessarily long. For some while, the following approach has been given here :- function ValidDate(y, m, d) { // m = 0..11 ; y m d...
11
4631
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 having a heck of a time doing so. I have created a form where I use drop downs do specify year, month, date, hour, minute and seconds. When the...
2
7326
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. Is there anyway to disable this?
1
1630
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 date is going into the database. Need to be able to perform calculations on the dates in order for newly added notes to show up in bold on a...
5
3243
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 that seems barbaric... Anything neater? Cheers Simon Ps, Im also just trying to work out how to calculate the number of mondays and tuesdays...
3
2710
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
7760
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7679
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8049
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5284
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3723
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2185
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1289
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1029
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.