Today is 6/22/2004, so if you're reading this on a different day, assume that Now() is 6/22/2004.
Example 1: When I run this example, I would think that it would give me a value of 1, but diff turns out to be 0.
date1 = CreateDate(2004, 6, 23);
date2 = Now();
diff = DateDiff("D", date2, date1);
Example 2: Given that the above example gives me a value of 0, I decided to check to see what comparing the current date to itself would give (but again using CreateDate to create one of the dates).
date1 = CreateDate(2004, 6, 22);
date2 = Now();
diff = DateDiff("D", date2, date1);
Again diff is 0. I guess this is my confusion--how can comparing the date to itself AND the date to tomorrow BOTH give me a value of 0?
Example 3: To make sure it wasn't the CreateDate() function that was doing something weird, I did the following, and it STILL gives me a value of 0:
date3 = DateAdd("D", 1, Now());
date4 = Now();
diff2 = DateDiff("D", date4, date3);
Example 4: Now for the total weirdness. When I put a couple of examples together, one AFFECTS the other. In the first round, diff = 0 and diff2 = 1:
date1 = CreateDate(2004, 6, 22);
date2 = Now();
diff = DateDiff("D", date2, date1);
WriteOutput("diff = " & diff & "<br />");
date3 = DateAdd("D", 1, Now());
date4 = Now();
diff2 = DateDiff("D", date4, date3);
WriteOutput("diff2 = " & diff2 & "<br />");
But when I chnage it to this:
date1 = CreateDate(2004, 6, 23);
date2 = Now();
diff = DateDiff("D", date2, date1);
WriteOutput("diff = " & diff & "<br />");
date3 = DateAdd("D", 1, Now());
date4 = Now();
diff2 = DateDiff("D", date4, date3);
WriteOutput("diff2 = " & diff2 & "<br />");
BOTH diff and diff2 = 0. I've tried this on both CFMX 6.1 on Windows 2003 as well as BlueDragon on Mac OS X and I see the same behavior.
Again, I'm sure I'm just having a fundamental misunderstanding of DateDiff since I've never had to mess with it much, so any enlightment on this will be greatly appreciated.
Thanks,
Matt
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

