DontellTrevell via AccessMonster.com wrote:
Wow!!...Let me start over......Here's what I'm tring to do: I have 2
date fields [StartDate] & [EndDate] from an ODBC table that are TEXT
fields. How can I simply convert from text to serial so I can
perform the calculation. Can I use the query criteria? If so, what
do I type in the query criteria?
So what you have are Text fields that happen to contain only digits that
happen to represent dates. (even sounds silly doesn't it?)
If these are text then you are going to need to go through multiple
conversions or split the string up and use one conversion. The DateValue()
function needs a date or a string that looks like a date. If we insert
dashes into your string that will give us a good string that looks like a
date, but to insert the dashes with the Format() function we first have to
convert the string to a number and then the Format function will give that
back to us as a String again.
DateValue(Format(CLng([StartDate]),"0000-00-00"))
You might get away with omitting the CLng() function above but Access will
still be coercing the string to a number in the background so it is better
practice to just explicitly do it yourself.
You could also split the string up and feed that to the DateValue() function
like this...
DateValue(Left([StartDate],4) & "-" & Mid([StartDate],5,2) & "-" &
Right([StartDate],2))
While that is longer it involves fewer data type conversions. I have no
idea if you would notice a speed difference. So using the first example
your date difference would be found with...
DateValue(Format(CLng([EndDate]),"0000-00-00")) -
DateValue(Format(CLng([StartDate]),"0000-00-00"))
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com