473,796 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ 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 1662
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.c om...
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.c om...
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:3 0 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..h a...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
4754
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 OLTP DB to a the target Operational Data Store. This is still in development so both DB's reside on the same machine for convenience. The stored proc runs successfully from within Query analyzer and this holds true on the following platforms: XP...
6
1801
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 coming from. Can you help? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD>
3
1695
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 happening. I have two text boxes. One is for the ID number, which when postback occurs, inserts into the related table as the foreign key. The other text box is for notes that go along side the foreign key of the the related table. Basically, the...
1
7000
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 out of the range of valid values. Parameter name: utcDate Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in...
0
9679
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9527
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
10453
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10172
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9050
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...
0
5441
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...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
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.