I have the following code. If I do the dateadd function with
dateinterval.mi nute, it works fine and the date/time value is displayed with
zero seconds. If I do the dateadd function with dateinterval.se cond, 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 = &H1C5EA3B5F585F 1F
Const dateRef As Date = #1/1/1601#
TextBox1.Text = CStr(DateAdd(Da teInterval.Minu te, CDbl(largeInteg er
/ (60 * 10000000)), dateRef))
'TextBox1.Text = CStr(DateAdd(Da teInterval.Seco nd, CDbl(largeInteg er
/ 10000000), dateRef))
I am doing this in Visual Web Developer Express. 2 4553
Rich Raffenetti wrote: I have the following code. If I do the dateadd function with dateinterval.mi nute, it works fine and the date/time value is displayed with zero seconds. If I do the dateadd function with dateinterval.se cond, 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 = &H1C5EA3B5F585F 1F Const dateRef As Date = #1/1/1601# TextBox1.Text = CStr(DateAdd(Da teInterval.Minu te, CDbl(largeInteg er / (60 * 10000000)), dateRef)) 'TextBox1.Text = CStr(DateAdd(Da teInterval.Seco nd, CDbl(largeInteg er / 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(DateIn terval.Second,2 147000000,now)
#2/23/2074 3:49:47 AM#
?dateadd(DateIn terval.Second,2 148000000,now)
overflow exception
Workaround (well, fix): don't use the legacy VB functions; the
Framework's date handling is better:
TextBox1.Text = dateRef.AddMinu tes(CDbl(largeI nteger / (60 *
10000000))).ToS tring
'or
TextBox1.Text = dateRef.AddSeco nds(CDbl(largeI nteger /
10000000)).ToSt ring
'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
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*******@hotm ail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. . Rich Raffenetti wrote: I have the following code. If I do the dateadd function with dateinterval.mi nute, it works fine and the date/time value is displayed with zero seconds. If I do the dateadd function with dateinterval.se cond, 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 = &H1C5EA3B5F585F 1F Const dateRef As Date = #1/1/1601# TextBox1.Text = CStr(DateAdd(Da teInterval.Minu te, CDbl(largeInteg er / (60 * 10000000)), dateRef)) 'TextBox1.Text = CStr(DateAdd(Da teInterval.Seco nd, CDbl(largeInteg er / 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(DateIn terval.Second,2 147000000,now) #2/23/2074 3:49:47 AM# ?dateadd(DateIn terval.Second,2 148000000,now) overflow exception
Workaround (well, fix): don't use the legacy VB functions; the Framework's date handling is better:
TextBox1.Text = dateRef.AddMinu tes(CDbl(largeI nteger / (60 * 10000000))).ToS tring 'or TextBox1.Text = dateRef.AddSeco nds(CDbl(largeI nteger / 10000000)).ToSt ring '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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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)
response.write testdate & "<br>"
|
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 function
in postgre. Can you help me?
The function in MSDE is the following:
ALTER FUNCTION dbo.slisp
(
@UCESTALOST_BROJ int,
@UCESTALOST_JEDINICA nvarchar (50),
|
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 dateadd(year,1,dateadd(month,-1,getdate()))
AND dateadd(day,-1,(dateadd(month,1,dateadd(year,1,dateadd(month,-1,getdate())))))
***************
(first part of the date calculation comes out to be '2005-05-01' and
|
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
which is logical correct? But I want it to return end of month (i.e.
20041231)
Any help in this context will be highly appreciated
|
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 blank. I've tried;
>
>DateDiff("y",-4,DateIn) and get errors
>
>Please any assistance would be greatly appreciated.
>
| |
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() ' if the table is in the same database
Set rsAdd = db.OpenRecordset("tblClientTreatment")
With rsAdd
.AddNew
!ClientID = Me.ClientID
|
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 function for the
beginning of the date range, like this:
Between DateAdd("m",-1,!!) And
!!
|
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 AM",
no date
Example direct from VB Language Reference:
Public Overloads Function DateAdd(ByVal Interval As DateInterval,_
ByVal Number As Double, ByVal DateValue As DateTime) As DateTime
End Function
|
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 function
in postgre. Can you help me?
The function in MSDE is the following:
ALTER FUNCTION dbo.slisp
(
@UCESTALOST_BROJ int,
@UCESTALOST_JEDINICA nvarchar (50),
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |