[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bump::msaccess

Title:MSACCESS
Moderator:BUMP::HONER
Created:Tue Dec 01 1992
Last Modified:Mon Jun 02 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1661
Total number of notes:6339

1637.0. "YET ANOTHER DATE PROBLEM.." by POLAR::GOSLING (KAO - 621-4519) Wed Mar 05 1997 14:44

I know the answer to this is looking me right in the face, but I'll be
darned if I can see it. Something that I thought would be simple has got
me completely baffled.

I have a need to read a date string from a file I created using the Write
function (note that all this is done in / with ACCESS V2). I need to
convert that string to a date / date format as I want to be able to
manipulate / use that date in my program. Also, while I am asking the
question about the first instance of a date, there are other date - and
indeed time - strings that I need to get and work with (including writing
the date to a record in a table), so I'm hoping by solving the first one,
the same logic will be / can be applied to the balance.

The line in question is produced by the following (this is essentially a
date stamp of when the file was created):

        Write #1, "File Date - ", now
        
Where #1 = c:\testfile.txt
        
When c:\testfile.txt is viewed via a text editor the result of the above
is:

        "File Date - ",#1997-03-04 12:20:27#
        
Reading the file and using the mid($) function, I have been able to
extract the #1997-03-04 12:20:27# part of this line and assign it to the
variable FileDate. Problem is I can't subsequently convert this to a
date!!

If I put a Stop in the code and muck around in the Immediate Window, some
interesting - but frustrating - things come to light / happen.

 ?FileDate yields #1997-03-04 12:20:27#
 ?vartype(FileDate) yeilds 8 (a string)
 ?isdate(FileDate) yeilds 0 (false - not a date)
 ?cvdate(FileDate) results in a Type Mismatch error
 
If I cut and paste the literal #1997-03-04 12:20:27# into the cvdate
function I get

 ?cvdate(#1997-03-04 12:20:27#)
 3/4/97 12:20:27 PM
 
If I reset FileDate to the literal and check if it is a date I get:

 Filedate = #1997-03-04 12:20:27#
 ?isdate(FileDate) yeilds -1 (true - is a date)
         
I have tried about a million different approaches to get the results I'm
looking for, which is the ability to simply take the date string, assign
it to a variable and make that variable a date!! How come the literal
works but variable doesn't?

I have looked through the date (dir/title=date) related topics in this
Conference, plus checked the V2 Knowledge Base with no luck or
satisfaction. A lot of stuff that skirts around date related issues, but
nothing that jumps out as "...this is the solution to your problem...".

Any suggestions would be greatly appreciated.

Art 
T.RTitleUserPersonal
Name
DateLines
1637.1RE: YET ANOTHER DATE PROBLEM..NETRIX::"laodennis@mail.dec.com"Dennis LaoThu Mar 06 1997 04:0518
Art,

the answer is staring you in the face. The cvdate() function is what you are
after.

Here's an example:

    Dim DateVar As Variant

    'Assign DateString to Date Variable
    DateVar = CVDate(#4/03/97 12:20:27#)
    'Manipulate date i.e. add one year to date
    Debug.Print DateAdd("yyyy", 1, DateVar)

Hope this helps.

Dennis.
[Posted by WWW Notes gateway]
1637.2NOT QUITE...POLAR::GOSLINGKAO - 621-4519Thu Mar 06 1997 20:0525
    Re: <<< Note 1637.1 by NETRIX::"laodennis@mail.dec.com" "Dennis Lao" >>>

Dennis,

Thanks for the quick response. Unfortunately it really doesn't solve my
particular problem - unless I am missing something.

What you did, and what I did try and was successful at (see the base
note) is assign the literal date string to a variable and convert it to a
date and use it as such. Problem comes when I extract what appears to be
a legitimate date string from a file, assign that string to a variable
and then try to do the convert that variable to a date. It is at that
time I get the Type Mismatch error.

Again, logic is as follows:

1st Line of text file being read is "File Date - ",#1997-03-03 12:20:27#.
Read it and assign it to a variable TextLine ie. Line Input #1,TextLine

Using Mid$ function extract #1997-03-04 12:20:27# and assign to a
variable DateVar ie. DateVar = Mid$(textline, 16, 21)

Now, do a CVDate(DateVar) and you will get the Type Mismatch error.

Art
1637.3BUSY::SLABEnjoy what you doThu Mar 06 1997 20:4811
    
    	Should you be including the #'s in your variable assignment?
    
    	IE, maybe mid$(textline,17,19) instead?
    
    
    	But if the #'s should be there, what do they do?  Looks like
    	their only purpose would be to "enclose" the date so that
    	there is no gap in the field [created by the space between
    	the date and time].
    
1637.4#date literal#NSIC00::KLERKThunderbirds are GoFri Mar 07 1997 07:0210
From the MS Access help file:

date literal

Any sequence of characters with a valid format that is surrounded by number
signs (#).  Valid formats include the date format specified by the locale
settings for your code or the universal date format.
For example, #12/31/92# is the date literal that represents December 31, 1992
where English-U.S. is the locale setting for your application.  Use date
literals to maximize portability across national languages.
1637.5BUSY::SLABForeplay? What's that?Fri Mar 07 1997 13:223
    
    	Thanks, I sort of figured.
    
1637.6Solution to the problemNETRIX::&quot;laodennis@mail.dec.com&quot;Dennis LaoFri Mar 14 1997 04:4517
Hope this is not too late...

> 1st Line of text file being read is "File Date - ",#1997-03-03 12:20:27#.
> Read it and assign it to a variable TextLine ie. Line Input #1,TextLine
>
> Using Mid$ function extract #1997-03-04 12:20:27# and assign to a
> variable DateVar ie. DateVar = Mid$(textline, 16, 21)
> 
> Now, do a CVDate(DateVar) and you will get the Type Mismatch error.

This is because Access does not like the yyyy-mm-dd format. You will need to
massage TextLine so that the date portion is in the format mm-dd-yyyy before
passing it on to CVDate.

Regards,
Dennis.
[Posted by WWW Notes gateway]
1637.7Came at it from another direction...POLAR::GOSLINGKAO - 621-4519Mon Mar 31 1997 13:4623
        Re:      <<< Note 1637.6 by NETRIX::"laodennis@mail.dec.com" "Dennis Lao" >>>

Dennis,

I have worked around what I consider an inconsistency - so not solved my
original problem, just come at it a different way.

Indeed the format yyyy-mm-dd is legal and can be processed as such. The
issue is one of how you process it. 

If I use the LINE INPUT # statement and parse the line to extract the
date, I can't get the darn thing converted to a date format.

If I use the LINE # statement, in which I am forced to pre-dimension that
part of the line being read as a Variant, then the same information gets
'input' as a date.

Again, I have worked around the problem by changing my code to the
latter. I am still curious as to why the former parsing and converting of
a string to a date variant doesn't work.

Art