Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 14th, 2004, 03:41 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default DateDiff Weirdness

I just discovered that DateDiff can give you a wrong answer if you were expecting what I was, so I wanted share it.

If you have Date1 = #12/31/2003# and Date2 = #1/1/2004#, then

Int((Date2 - Date1) / 365.25) = 0


DateDiff("yyyy", Date1, Date2) = 1

I thought this was a bug because clearly only one day has passed so the DateDiff should return zero also. But in the DateDiff help it says:
quote:When comparing December 31 to January 1 of the immediately succeeding year, DateDiff for Year ("yyyy") returns 1 even though only a day has elapsed.
I also noticed that counting months and weeks ("m" and "ww", respectively) are wrong, too.

This is terrible... DateDiff should return the true number of months and years elapsed, not just subtract the month or year parts from each other!

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division
Reply With Quote
  #2 (permalink)  
Old July 16th, 2004, 12:38 AM
Friend of Wrox
Join Date: Jun 2003
Location: Melbourne, Vic, Australia.
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts

I came across a similar thing in December:

But I think it makes perfect sense now.
If you want to find the difference in years between two dates, then DateDiff("yyyy", Date1, Date2) is perfect.
If you want to do real calculations with Dates, then I'd just use Date1-Date2 and Multiply/Divide it by however you want it formatted.


I am a loud man with a very large hat. This means I am in charge
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Array weirdness? oldmainframehack Beginning PHP 1 September 5th, 2007 03:24 PM
Session variable weirdness LenexaKS ASP.NET 2.0 Professional 5 June 4th, 2007 11:05 AM
DropDownList.SelectedValue weirdness Aaron Edwards ASP.NET 2.0 Basics 5 March 7th, 2007 12:39 AM
GridView HeaderStyle Weirdness Bob Bedell ASP.NET 2.0 Basics 2 December 25th, 2006 02:28 PM

All times are GMT -4. The time now is 02:19 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.