|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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. Rich Raffenetti wrote:
Show quoteHide quote > I have the following code. If I do the dateadd function with I'd say this counts as a bug. The DateAdd function, despite asking for> 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. 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 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 Show quoteHide quote "Larry Lard" <larryl***@hotmail.com> wrote in message news:1139583364.826212.247200@g14g2000cwa.googlegroups.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 >
Create Local Administrator
Cdbl & International Settings can you add onMouseOver/onMouseOut to an ImageButton?? Eschewing the Form Designer VB.NET (2005); Sqlce ? How to hide one column in datagrid? Hex with leading zeros to string? Dynamically remove child controls ? Step by step it works but... vb.net windows application that connects to the net. |
|||||||||||||||||||||||