By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Seeking opinions on code that utilizes internal represention of dates

P: n/a
A.K.A. Is Double Dating a bad thing :-)? My post from several hours
ago may have gotten lost so please forgive me if something similar to
this shows up twice. From a modular programming class I took many
years ago I was taught that it is important to maintain a good
interface to hidden code so that when updates are created they can be
tested and swapped into place without the program having to know the
details of the hidden code. The representation of dates in access as a
Double doesn't seem to be about to change anytime soon, if ever.
Taking advantage of how dates are represented in Access often results
in cleaner, more elegant code. Nevertheless, the modular programming
philosophy makes me wonder if this is actually poor coding practice or
at least not as robust as, for example, using DateAdd to increment a
date. This seems picayune to me so I don't want the issue to become
dogma or result in the beating an expired equine, but (the comma was
necessary :-)) I would be interested in hearing the opinions of others
on this. I note somewhat parenthetically that back in QBasic's heyday
I rolled my own DateDiff function using, IIRC, a yyyymmdd string as my
representation for dates since putting the smallest unit in the middle
didn't seem uniform or advantageous.

Thanks in Advance,

James A. Fortune
CD********@FortuneJames.com

Jan 7 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
CD********@FortuneJames.com wrote in news:1136534687.071079.157050
@g44g2000cwa.googlegroups.com:
A.K.A. Is Double Dating a bad thing :-)? My post from several hours
ago may have gotten lost so please forgive me if something similar to
this shows up twice. From a modular programming class I took many
years ago I was taught that it is important to maintain a good
interface to hidden code so that when updates are created they can be
tested and swapped into place without the program having to know the
details of the hidden code. The representation of dates in access as a
Double doesn't seem to be about to change anytime soon, if ever.
Taking advantage of how dates are represented in Access often results
in cleaner, more elegant code. Nevertheless, the modular programming
philosophy makes me wonder if this is actually poor coding practice or
at least not as robust as, for example, using DateAdd to increment a
date. This seems picayune to me so I don't want the issue to become
dogma or result in the beating an expired equine, but (the comma was
necessary :-)) I would be interested in hearing the opinions of others
on this. I note somewhat parenthetically that back in QBasic's heyday
I rolled my own DateDiff function using, IIRC, a yyyymmdd string as my
representation for dates since putting the smallest unit in the middle
didn't seem uniform or advantageous.


My response from several hours ago may have gotten lost so please forgive
me if something similar to this shows up twice.

Yes, it is a bad thing.

1. It is not intellectually sound. Dates are not Doubles. Dates do not
behave as Doubles do. There is no reason of convenience or simplicity
which can make up for a fundamental flaw in thinking and this is a
fundamental flaw. At anytime in code it may hover there, waiting to
delude both the creator and the user. In high school of many years ago I
was taught that x/0 = infinity. This may have been a simple explanation
suitable for young minds and those of the teachers. But it is wrong. And
it should never have been used.

2. It is unreliable and it can be invalid.

Option Explicit

Sub temp()
Dim d As Date
d = -(1 / 2)
Debug.Print "--------"
Debug.Print _
" The date d is:", _
Format(d, "yyyy mm dd hh:nn:ss")
Debug.Print _
" The date d + 1 is:", _
Format(d + 1, "yyyy mm dd hh:nn:ss")
'--------
'The date d is: 1899 12 30 12:00:00
'The date d + 1 is: 1899 12 30 12:00:00
End Sub

Sub temp2()
Dim b As String
Dim d(2) As Date
d(0) = VBA.Date()
d(1) = d(0) + 0.000001
If d(0) = d(1) Then
b = "is equal to"
Else
b = "is not equal to"
End If
Debug.Print "--------"
Debug.Print Format(d(0), "yyyy mm dd hh:nn:ss")
Debug.Print b
Debug.Print Format(d(1), "yyyy mm dd hh:nn:ss")
Debug.Print "They are"
Debug.Print DateDiff("s", d(1), d(0))
Debug.Print "seconds apart."
'--------
'2006 01 07 00:00:00
'is not equal to
'2006 01 07 00:00:00
'They are
'0
'seconds apart.
End Sub
--
Lyle Fairfield
Jan 7 '06 #2

P: n/a
CD********@FortuneJames.com wrote:
A.K.A. Is Double Dating a bad thing :-)? My post from several hours
ago may have gotten lost so please forgive me if something similar to
this shows up twice.


Sometimes Google code for posting use some old modules that treat Dates
as Doubles. This must have been what happened!

Jan 7 '06 #3

P: n/a
Lyle Fairfield wrote:
CD********@FortuneJames.com wrote:
A.K.A. Is Double Dating a bad thing :-)? My post from several hours
ago may have gotten lost so please forgive me if something similar to
this shows up twice.


Sometimes Google code for posting use some old modules that treat Dates
as Doubles. This must have been what happened!


Ha! Thanks for your advice. I'll try to avoid that trap in the future.

James A. Fortune
CD********@FortuneJames.com

Jan 9 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.