PC Review


Reply
Thread Tools Rate Thread

Bug in a built-in VBA date function?

 
 
suomi
Guest
Posts: n/a
 
      9th Jan 2007
Hi all,

Is this a bug or my misunderstanding with date VBA functions: DateDiff
and DateAdd:
The DateDiff function returns always an integer, which I suppose mean,
that between 2 dates there is at least full period of difference. In
other words, DateDiff function does not round, but cuts off the decimal
places in the value of difference. Now look at example:

ActiveCell.Value = DateDiff("q", Date, "2007-04-06")
ActiveCell.Offset(1, 0).Value = DateAdd("q", 1, Date)

Date is a today's date, when I performed it, it was the 9th of January.
As a result I got:

1,0000
2007-04-09

>From the first row, I suppose, that between 2007-01-09 and 2007-04-06

there is at least one quarter, or one quarter with decimal places
after. I checked, and the boundary date is here 2007-04-01, which means
that I shall be sure there's one quarter and a bit more of difference.
So I supposed, that adding one (1, without decimal places) quarter to
2007-01-09 would return 2007-04-01. But it did not. It returned
2007-04-09. Why?

I need these functions for this kind of task: I have a date and I need
to find an approriate date before and after this one given, so, that
the found dates are the beginning of two adjacent "full" periods, like
quarters.

Any advice on this issue?

 
Reply With Quote
 
 
 
 
Jim Rech
Guest
Posts: n/a
 
      9th Jan 2007
Datediff (with 'q' at least) does not seem to be suited to your needs. This
returns 1:

DateDiff("q", "2007-03-31", "2007-04-01")

It seems to find the quarter number each date is in and return that
difference.

--
Jim
"suomi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| Hi all,
|
| Is this a bug or my misunderstanding with date VBA functions: DateDiff
| and DateAdd:
| The DateDiff function returns always an integer, which I suppose mean,
| that between 2 dates there is at least full period of difference. In
| other words, DateDiff function does not round, but cuts off the decimal
| places in the value of difference. Now look at example:
|
| ActiveCell.Value = DateDiff("q", Date, "2007-04-06")
| ActiveCell.Offset(1, 0).Value = DateAdd("q", 1, Date)
|
| Date is a today's date, when I performed it, it was the 9th of January.
| As a result I got:
|
| 1,0000
| 2007-04-09
|
| >From the first row, I suppose, that between 2007-01-09 and 2007-04-06
| there is at least one quarter, or one quarter with decimal places
| after. I checked, and the boundary date is here 2007-04-01, which means
| that I shall be sure there's one quarter and a bit more of difference.
| So I supposed, that adding one (1, without decimal places) quarter to
| 2007-01-09 would return 2007-04-01. But it did not. It returned
| 2007-04-09. Why?
|
| I need these functions for this kind of task: I have a date and I need
| to find an approriate date before and after this one given, so, that
| the found dates are the beginning of two adjacent "full" periods, like
| quarters.
|
| Any advice on this issue?
|


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Rate() built-in function Burnett71 Microsoft Access VBA Modules 3 27th Oct 2009 04:06 PM
custom function - with built-in function VilMarci Microsoft Excel Programming 14 25th Jan 2005 04:15 PM
Built-in Addins do not Function Wayne Coutts Microsoft Access 1 10th Jun 2004 03:21 PM
CDate built in function student Microsoft Access 1 23rd Sep 2003 03:29 AM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Microsoft Excel Programming 1 6th Aug 2003 09:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:44 PM.