|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DateDiff(DateInterval.DayOfYearWhy is the DateDiff function in the following code returning zero?
Dim FileDate, TransmissionDate as Date Dim TranDay, FileDay, DayDiff as Inteter TransmissionDate = #2/5/2006 1:57:56 PM# FileDate = #2/4/2006 4:49:02 PM# TranDay = DatePart(DateInterval.DayOfYear, TransmissionDate) 'Returns 36 FileDay = DatePart(DateInterval.DayOfYear, FileDate) 'Returns 35 DayDiff = DateDiff(DateInterval.DayOfYear, FileDate, TransmissionDate) 'Returns 0 -- Price Brattin Certified MBS/Solomon Consultant SQLServer MCP VB.Net Developer Price,
I did not do it, however can you change your sample in Dim TranDay, FileDay, DayDiff as Double and than try it again. Most calculations inside Net are done with doubles. Cor I will give it a try but I am puzzled what it would mean. DatePart returns
an integer and DateDiff returns a long. Declaring those fields as Double would mean converting an integer to a Double. The purpose of showing the values returned was to show that DatePart does recognize the dates as different days but DateDiff does not. Why is that so? -- Show quoteHide quotePrice Brattin Certified MBS/Solomon Consultant SQLServer MCP VB.Net Developer "Cor Ligthert [MVP]" wrote: > Price, > > I did not do it, however can you change your sample in > Dim TranDay, FileDay, DayDiff as Double and than try it again. > > Most calculations inside Net are done with doubles. > > Cor > > > Hello, Price,
It appears that DateDiff returns only the number of complete time intervals elapsed. In effect it is truncating the difference to the next smaller integer, rather than rounding it as you might expect. So for example, the difference is still zero (full) days even if the Transmission date is #2/5/2006 4:49:01 PM#. But add just one more second, and the difference will become one (full) day. Note that this behaviour of DateDiff is not consistent. (And this is mentioned/implied in the documentation.) In the case of DateInterval.Year, the non-year portion of the date is disregarded, so that (for example): DateDiff(DateInterval.Year, _ #12/31/2005 11:59:59 PM#, _ #1/1/2006 12:00:01 AM#) returns a value of 1! DateInterval.Month appears to work the same way as DateInterval.Year. (You've gotta love the programmer that thought implementing DateDiff with this inconsistency would be a good idea. I guess that he got overwhelmed with the concepts involved in DateInterval.Weekday and DateInterval.WeekOfYear. :( ) Cheers, Randy Price Brattin wrote: Show quoteHide quote > Why is the DateDiff function in the following code returning zero? > > Dim FileDate, TransmissionDate as Date > Dim TranDay, FileDay, DayDiff as Inteter > TransmissionDate = #2/5/2006 1:57:56 PM# > FileDate = #2/4/2006 4:49:02 PM# > TranDay = DatePart(DateInterval.DayOfYear, TransmissionDate) 'Returns 36 > FileDay = DatePart(DateInterval.DayOfYear, FileDate) 'Returns 35 > DayDiff = DateDiff(DateInterval.DayOfYear, FileDate, TransmissionDate) > 'Returns 0 > > >
Combobox in VB2005
problem with relative paths in VS/VB.net making image click fire codebehind function? newbie problem with array Problem Communicating Between Forms Calling Program A from Program B help with multiple forms on asp.net 1.1 page, please Class as an array Download free ebooks Visual Basic 2005 Jumpstart |
|||||||||||||||||||||||