Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Bug in a built-in VBA date function?

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?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Bug in a built-in VBA date function?

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" wrote in message
oups.com...
| 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
is there any built in function to draw lines krishnan Excel Worksheet Functions 2 June 22nd 09 01:31 PM
Now not regonized as a built in Function, in some spreadsheets? Craigm[_55_] Excel Programming 5 May 8th 06 05:26 PM
Use An Excel Built-In Function Entirely Within VBA MDW Excel Programming 3 February 23rd 06 10:03 PM
Access Recordset with Built-In Function Jeff Huff Excel Programming 3 November 10th 03 10:08 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 05:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"