473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DateAdd function malfunctions?

I have the following code. If I do the dateadd function with
dateinterval.minute, it works fine and the date/time value is displayed with
zero seconds. If I do the dateadd function with dateinterval.second, an
error is thrown saying I have an overflow. I would be happy to know if I am
doing something wrong or if I could do it differently to get the seconds to
display properly.

Const largeInteger As Long = &H1C5EA3B5F585F1F
Const dateRef As Date = #1/1/1601#
TextBox1.Text = CStr(DateAdd(DateInterval.Minute, CDbl(largeInteger
/ (60 * 10000000)), dateRef))
'TextBox1.Text = CStr(DateAdd(DateInterval.Second, CDbl(largeInteger
/ 10000000), dateRef))

I am doing this in Visual Web Developer Express.
Feb 10 '06 #1
2 4533

Rich Raffenetti wrote:
I have the following code. If I do the dateadd function with
dateinterval.minute, it works fine and the date/time value is displayed with
zero seconds. If I do the dateadd function with dateinterval.second, an
error is thrown saying I have an overflow. I would be happy to know if I am
doing something wrong or if I could do it differently to get the seconds to
display properly.

Const largeInteger As Long = &H1C5EA3B5F585F1F
Const dateRef As Date = #1/1/1601#
TextBox1.Text = CStr(DateAdd(DateInterval.Minute, CDbl(largeInteger
/ (60 * 10000000)), dateRef))
'TextBox1.Text = CStr(DateAdd(DateInterval.Second, CDbl(largeInteger
/ 10000000), dateRef))

I am doing this in Visual Web Developer Express.


I'd say this counts as a bug. The DateAdd function, despite asking for
a Double as its second argument, seems to be converting that double to
an Int32 at some point. Evidence:

?dateadd(DateInterval.Second,2147000000,now)
#2/23/2074 3:49:47 AM#
?dateadd(DateInterval.Second,2148000000,now)
overflow exception

Workaround (well, fix): don't use the legacy VB functions; the
Framework's date handling is better:

TextBox1.Text = dateRef.AddMinutes(CDbl(largeInteger / (60 *
10000000))).ToString
'or
TextBox1.Text = dateRef.AddSeconds(CDbl(largeInteger /
10000000)).ToString
'both work fine

Even better (in terms of self-documenting code), convert largeInteger
to a TimeSpan (documenting the conversion factor), then just add it to
dateref.
--
Larry Lard
Replies to group please

Feb 10 '06 #2
Larry,
Thanks a load. It works great! I was hoping for a different way like
this. It's not always clear what is legacy.

Do you recommend any reference books that describe these nitty-gritty
details for .Net?
Rich

"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

Rich Raffenetti wrote:
I have the following code. If I do the dateadd function with
dateinterval.minute, it works fine and the date/time value is displayed
with
zero seconds. If I do the dateadd function with dateinterval.second, an
error is thrown saying I have an overflow. I would be happy to know if I
am
doing something wrong or if I could do it differently to get the seconds
to
display properly.

Const largeInteger As Long = &H1C5EA3B5F585F1F
Const dateRef As Date = #1/1/1601#
TextBox1.Text = CStr(DateAdd(DateInterval.Minute,
CDbl(largeInteger
/ (60 * 10000000)), dateRef))
'TextBox1.Text = CStr(DateAdd(DateInterval.Second,
CDbl(largeInteger
/ 10000000), dateRef))

I am doing this in Visual Web Developer Express.


I'd say this counts as a bug. The DateAdd function, despite asking for
a Double as its second argument, seems to be converting that double to
an Int32 at some point. Evidence:

?dateadd(DateInterval.Second,2147000000,now)
#2/23/2074 3:49:47 AM#
?dateadd(DateInterval.Second,2148000000,now)
overflow exception

Workaround (well, fix): don't use the legacy VB functions; the
Framework's date handling is better:

TextBox1.Text = dateRef.AddMinutes(CDbl(largeInteger / (60 *
10000000))).ToString
'or
TextBox1.Text = dateRef.AddSeconds(CDbl(largeInteger /
10000000)).ToString
'both work fine

Even better (in terms of self-documenting code), convert largeInteger
to a TimeSpan (documenting the conversion factor), then just add it to
dateref.
--
Larry Lard
Replies to group please

Feb 11 '06 #3

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

Similar topics

3
by: Gabe | last post by:
Please see: http://www.showorders.com/test3.asp The code generating the page is as follows: testdate = "1/29/2003 1:00:00 PM" while count <> 5 testdate = dateadd("n",15,testdate)...
0
by: Zlatko Matić | last post by:
I am currently migrating from MSDE to PostgreSQL and have to rewrite the function that is calculating next date of sampling... In MSDE there is a DateAdd function. I can't find the appropriate...
1
by: Raghu | last post by:
Hello... I am running into a problem while running a query..can some1 help.. this is the query : ************** SELECT * from Table S where S.dtDate1 BETWEEN...
2
by: Abdul N K | last post by:
I need help in T-SQL. I am using DATEADD function and I want to add 6 months to a date. But it does not return me the rusults, which I want e.g. SELECT DATEADD(m,'20040630') returns 20041230...
1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
3
by: Annette Massie | last post by:
I am trying to insert a record into a table via code and one of the values to add I would like as a dateadd calculation on a value from a query. My code looks like this: Set db = CurrentDb() ...
4
by: ey.markov | last post by:
Greetings, I have an A2K application where for a report the user enters a month-end date, and the system must gather transactions for that month. No problem, I thought, I'll just use the DateAdd...
1
by: C.Davidson | last post by:
Does subject VB.net 2003 support DateAdd function? I have tried to implement the following without success. In my example I tried to simply add 30 months to 9/18/2003 and I get "New date: 12:00:00...
0
by: Zlatko Matić | last post by:
I am currently migrating from MSDE to PostgreSQL and have to rewrite the function that is calculating next date of sampling... In MSDE there is a DateAdd function. I can't find the appropriate...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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,...

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.