469,645 Members | 1,424 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

Can someone tell me what the significant difference between Date and Variant datatypes is?

MLH
If I choose to dim MyDate as Date or MyDate as Variant,
what is the most significant difference between the two
choices?
Nov 13 '05 #1
8 1693
MLH wrote:
If I choose to dim MyDate as Date or MyDate as Variant,
what is the most significant difference between the two
choices?


Variant can be anything (including a date) but it may interest you to
know that a variant can be null whereas a date cannot. Important if you
read values from a table (which can have nulls in).

--
[OO=00=OO]
Nov 13 '05 #2
MLH wrote:
If I choose to dim MyDate as Date or MyDate as Variant,
what is the most significant difference between the two
choices?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Date data type takes up 8 bytes in memory/storage and Variant can take
up to 16 bytes for numerics (that includes dates, since a date is stored
as a Double).

It's better to use a Date data type if you know that the data will
always be a date. I usually use Variants when I'm not sure if the
returned value from a query will be NULL or the data type I expect.
E.g.:

Dim varReturn As Variant

' run a routine that returns the result of a query:
varReturn = getQueryResult("query_name","param1","param_value" )

If IsNull(varReturn) Then
MsgBox "No Data Fits Your Criteria"
Else
' do something w/ the returned value
End If

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQtFnhoechKqOuFEgEQKCUACgi/eDbd0MOiwayA02tG2sn09dghUAoPLU
I7L6mkiZUM7HAM8dw6Yq97GY
=xRKd
-----END PGP SIGNATURE-----
Nov 13 '05 #3
MLH
Many thanks to you both. Very good information.
I didn't have Date datatype in Access 2.0 so I
wasn't familiar with it at all.
Nov 13 '05 #4
MLH <CR**@NorthState.net> wrote in
news:lk********************************@4ax.com:
Many thanks to you both. Very good information.
I didn't have Date datatype in Access 2.0 so I
wasn't familiar with it at all.


You shouldn't have used variant for dates in Access 2, but double as
your datatype, since that's what a data actually is, a double with
restrictions on allowed values. This is just as Boolean is an
integer with a restricted set of allowed values.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #5
MLH
Good point, I agree. Speaking of Boolean, why did MS make it so
big? We're only talking -1 and 0. Couldn't they have made it Byte
sized?

You shouldn't have used variant for dates in Access 2, but double as
your datatype, since that's what a data actually is, a double with
restrictions on allowed values. This is just as Boolean is an
integer with a restricted set of allowed values.


Nov 13 '05 #6
MLH <CR**@NorthState.net> wrote in
news:s2********************************@4ax.com:
You shouldn't have used variant for dates in Access 2, but double
as your datatype, since that's what a data actually is, a double
with restrictions on allowed values. This is just as Boolean is an
integer with a restricted set of allowed values.


Good point, I agree. Speaking of Boolean, why did MS make it so
big? We're only talking -1 and 0. Couldn't they have made it Byte
sized?


Actually, you're right -- it may be a Byte field. I was thinking
backwards to Access 2 days, when we had to use integer fields for it
(not having a Byte data type back then).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #7
MLH
I can't remember where I was reading just a couple of days ago, but
something there suggested to me it was two bytes in size in A97. I
thought that a waste of space. Granted, its not much, but hey...


Actually, you're right -- it may be a Byte field. I was thinking
backwards to Access 2 days, when we had to use integer fields for it
(not having a Byte data type back then).


Nov 13 '05 #8
I believe I remember that the 2-byte word gives better performance and can
be used in calculations in ways that a smaller value could not. Bytes, it
appears are (mostly) for containing characters, integers and longs are
(mostly) for doing calculation.

Larry Linson

"MLH" <CR**@NorthState.net> wrote in message
news:m5********************************@4ax.com...
I can't remember where I was reading just a couple of days ago, but
something there suggested to me it was two bytes in size in A97. I
thought that a waste of space. Granted, its not much, but hey...


Actually, you're right -- it may be a Byte field. I was thinking
backwards to Access 2 days, when we had to use integer fields for it
(not having a Byte data type back then).

Nov 13 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by androtech | last post: by
13 posts views Thread by Jason Huang | last post: by
11 posts views Thread by jwf | last post: by
3 posts views Thread by murch.alexander | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.