473,804 Members | 2,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateDiff(DateIn terval.DayOfYea r

Why is the DateDiff function in the following code returning zero?

Dim FileDate, TransmissionDat e as Date
Dim TranDay, FileDay, DayDiff as Inteter
TransmissionDat e = #2/5/2006 1:57:56 PM#
FileDate = #2/4/2006 4:49:02 PM#
TranDay = DatePart(DateIn terval.DayOfYea r, TransmissionDat e) 'Returns 36
FileDay = DatePart(DateIn terval.DayOfYea r, FileDate) 'Returns 35
DayDiff = DateDiff(DateIn terval.DayOfYea r, FileDate, TransmissionDat e)
'Returns 0

--
Price Brattin
Certified MBS/Solomon Consultant
SQLServer MCP
VB.Net Developer

Feb 5 '06 #1
3 13433
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
Feb 5 '06 #2
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?

--
Price 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

Feb 5 '06 #3
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.Ye ar, the non-year portion of the date is disregarded, so
that (for example):

DateDiff(DateIn terval.Year, _
#12/31/2005 11:59:59 PM#, _
#1/1/2006 12:00:01 AM#)

returns a value of 1! DateInterval.Mo nth appears to work the same way
as DateInterval.Ye ar. (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.We ekday and DateInterval.We ekOfYear. :( )

Cheers,
Randy
Price Brattin wrote:
Why is the DateDiff function in the following code returning zero?

Dim FileDate, TransmissionDat e as Date
Dim TranDay, FileDay, DayDiff as Inteter
TransmissionDat e = #2/5/2006 1:57:56 PM#
FileDate = #2/4/2006 4:49:02 PM#
TranDay = DatePart(DateIn terval.DayOfYea r, TransmissionDat e) 'Returns 36
FileDay = DatePart(DateIn terval.DayOfYea r, FileDate) 'Returns 35
DayDiff = DateDiff(DateIn terval.DayOfYea r, FileDate, TransmissionDat e)
'Returns 0

Feb 6 '06 #4

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

Similar topics

5
6345
by: Hinrich Specht | last post by:
Hi, I´d like to display anniversary greetings on my website. The annyversaries are saved in a mysql-table in the mysql DATE-Format (YYYY-MM-DD). Now I need to select all rows where the day and the month is between now and +7 days (to show the anniversaries coming up within the next week). My question is: Is there a way to select these rows directly from the DB without recognizing the year? Or do I have to query all rows and parse the...
4
2329
by: Tarscher | last post by:
Hi all, I have a l list of persons and birthdays (stored as a date eg: 1980-07-11). I want to query the 4 first persons that will have their birtday. Can this be done via query? Thanks in advance Stijn
0
2151
by: Peter Ruijter | last post by:
Hello, I've read and used the birthday solutions of Wolfgang Führer from the mySQL DATE examples on the mysql.com website. SELECT naam, gebdatum FROM users WHERE gebdatum != '0000-00-00' AND (( DAYOFYEAR(gebdatum) < DAYOFYEAR(now()) )*366)+DAYOFYEAR(gebdatum) >= DAYOFYEAR(now())ORDER BY (( DAYOFYEAR(gebdatum) < DAYOFYEAR(now()) )*366)+DAYOFYEAR(gebdatum)
14
18840
by: Des L. Davis | last post by:
System: Dell PowerEdge Server with 3 GB RAM, 2.4 GHz Celeron Software: Microsoft SQL Server 2000 Enterprise running on Windows 2003 Server Software: Microsoft SQL Server 2000 Enterprise running on Windows 2000 Server If you run the code below, you'll notice something odd occuring. The MilliSecond value does not change after a 1Millisecond delay. Is this a bug or am I doing something wrong? Any assistance will be greatly appreciated
8
1585
by: OzThor | last post by:
I have a javascript quiz webpage... that loads the questions and answers from a .js file... at this time i use the following to call the data <script src="quiz_a.js"></script> this works fine, but I'd like a new lot of data to be used each day... i have the javascript code to number each day of the year from 1 to 356 (or
10
2754
by: purkka | last post by:
Hi I did not find any solution from Internet how to do it. There is a lot of samples how to retrieve day of the week, but not number of the week. With rgds MP
2
1519
by: andrewcw | last post by:
There are probably a dozen really obnoxious ways to solve this : But I am trusting someone has a better idea than mine. The method calls below will tell me by the result= 0 if my program has reached another 2 week cycle. But once the year rolls over.. - Seems like I need to get the days not from year but the days from the beginning of time...( although I am not sure how to get that ...) or resort to some other roll over techniques.
1
3226
by: cjordan | last post by:
Hi everyone. I'm new here, and I think I've got a pretty unique problem (haven't found any solution to this anywhere else), but I'm hoping that someone here can help me. To be honest, I'm not a DB2 guy. I'm a contractor working for a client who uses a very old AS400 to do their payroll. They're running V5R3. I'm not sure if that refers to the version of DB2 or the version of the iSeries OS that we're running. Maybe they're the same thing. As...
8
1936
by: Gillard | last post by:
hello, anyone have a snippet to get the name of the season for a date???? something like GetSeason(today) and it return summer
0
9705
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
10568
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
10311
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
10074
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
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
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5516
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
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
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 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.