473,908 Members | 5,120 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 2119
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
2047
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 time on my server (off by about 5 minutes) and this throws off the elapsed time calculations. I know...
13
9325
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 to the MYSQL date field. The type of field is INT (11) so that I can instead of the standard...
2
5237
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
3715
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 integers, y!=0
11
4695
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 form is loaded, the dropdowns have to display the proper values for the current time zone type. This
2
7340
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
1651
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 report.
5
3268
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 etc between two dates... Just thought I'd run this
3
2724
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
9876
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10915
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10537
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8096
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5933
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4772
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
2
4336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3357
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.