473,471 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Strange date time error

I have a piece of code written in VS.NET 2003. It runs fine on one machine and does not on another. It throws an invalid cast
exception. Any idea why there is a difference between machines?

Dim CurDate As Date = Now
Dim SpecTime As Date = "#07:08:30 PM#"

Eception thrown here:
CurDate = SpecTime + CurDate

Nov 20 '05 #1
7 1647
I don't know about vs 2003 but you really just can't add dates any more..
use the
date.addseconds or minutes or hours method...

As to why the difference between machines ... It might be that the datetime
format settings on the machine are set different.

"Big Tony" <no**@somewhere.else.com> wrote in message
news:pm********************************@4ax.com...
I have a piece of code written in VS.NET 2003. It runs fine on one machine and does not on another. It throws an invalid cast exception. Any idea why there is a difference between machines?

Dim CurDate As Date = Now
Dim SpecTime As Date = "#07:08:30 PM#"

Eception thrown here:
CurDate = SpecTime + CurDate

Nov 20 '05 #2
The expression doesn't really make sense. You can add a date interval to
another date, but you can't add an absolute date to another date. It really
doesn't evaluate to anything meaningful. For example, you can add X number
of days or X number of minutes or X number of hours to the current
date/time Now. Below you can add 7 hours 8 minutes 30 seconds, which is an
interval but 7:08:30PM is not a time INTERVAL itself. The other thing you
can do is get the amount of time that has elapsed between two date
expressions, like how man hours have passed in between Now and 7:08:30PM.

In either case, you should be using date functions that were designed for
such calculations, like DateAdd or DateDiff.
"Big Tony" <no**@somewhere.else.com> wrote in message
news:pm********************************@4ax.com...
I have a piece of code written in VS.NET 2003. It runs fine on one machine and does not on another. It throws an invalid cast exception. Any idea why there is a difference between machines?

Dim CurDate As Date = Now
Dim SpecTime As Date = "#07:08:30 PM#"

Eception thrown here:
CurDate = SpecTime + CurDate

Nov 20 '05 #3
Cor
Hi Big Tony,
I think it could be
\\\\
Dim SpecTime As Date = CDate("#07:08:30 PM#")
/////
To overcome this kind of problems: Set Option Strict in the top of your
program to On.
Than you will get a message when there is such a kind of an error.
When you think you don't need that, don't use it.

I hope this helps.

Cor
Nov 20 '05 #4
"Big Tony" <no**@somewhere.else.com> schrieb
I have a piece of code written in VS.NET 2003. It runs fine on one
machine and does not on another. It throws an invalid cast exception.
Any idea why there is a difference between machines?

Dim CurDate As Date = Now
Dim SpecTime As Date = "#07:08:30 PM#"

Eception thrown here:
CurDate = SpecTime + CurDate


The code does not work here. "#07:08:30 PM" is a string whereas SpecTime is
a Date. Please enable Option Strict.

--
Armin

Nov 20 '05 #5
Cor
Hi Armin,
See my post, you will laugh
Cor
Nov 20 '05 #6
"Cor" <no*@non.com> schrieb
Hi Armin,
See my post, you will laugh
Cor


HAHAHAhahaha..ha...ha..hmmm.......

;-)

--
Armin

Nov 20 '05 #7
Hello,

You have to see regional parameters on each computer.

Pierre MAGINOT
Nov 20 '05 #8

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

Similar topics

24
by: LineVoltageHalogen | last post by:
Greetings All, I was hoping that someone out there has run into this issue before and can shed some light on it for me. I have a stored procedure that essentially does a mini ETL from a source...
6
by: WindAndWaves | last post by:
Hi Gurus The page below has a strange error. It seems to be working very well, just when you enter 8 or 9 for day, month or year then you get an error. I really have no idea where that is...
3
by: Jim in Arizona | last post by:
I'm going insane! I don't know if it's just that the .net 2.0 framework is buggy or if it really is my code. This is pretty hard to explain since I can't even begin to nail down why this is...
1
by: Victor | last post by:
Hi guys, I have a very strange problem with scriptmanager here. I want to load a js (which is embed in the project) but everytime i try to load that, it gives me error like Specified argument was...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.