Link to home
Start Free TrialLog in
Avatar of BHanson71
BHanson71

asked on

How can I parse a date from a string of text

I have a memo field that has notes and dates in it.  I want to parse the date from this field to run a report with.  The dates are in different positions depending on the amount of notes that goes with it
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Your description of the issue is vague. If you provide a few examples, it would be helpful.
you can extract the date using vba codes.
is there only a single date in the memo field?

function getThedate(vMemo as string)
dim j as integer, varArr() as string
vararr=split(vMemo," ")

for j=0 to ubound(varArr)
     'check the format of the varArr(j)
     if Isdate(varArr(j)) then
        ' we found a date
        getTheDate=varArr(j)
        exit function
     end if
end function


next
oops, error there

function getThedate(vMemo as string)
dim j as integer, varArr() as string
vararr=split(vMemo," ")

for j=0 to ubound(varArr)
     'check the format of the varArr(j)
     if Isdate(varArr(j)) then
        ' we found a date
        getTheDate=varArr(j)
        exit function
     end if
next
end function
Avatar of BHanson71
BHanson71

ASKER

Ok.  So I have a field called [Material] and it contains notes.  Usually looks something like "material due 9/25/15, component due 10/16/15".  I want to parse the first date to use in query.  What I am ultimately trying to do is say "Ok, 9/25/15 is next week.  Here's what's do."  I used the instr function. ex: NewField: InStr(1,[Material],"/") and then I used the mid function. ex:DueDate: Mid([Material],[NewField]-2,8).

My problem is that the dates vary in length from 6 to 8 characters.  I was looking for an easier way to just grab the date.
Thank you Rey.  I'd like to be able to do this in a Query though.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Might I suggest an application change?  DO NOT EMBED DATES IN STRINGS.  In addition to being a violation of first normal form, it is noting but trouble to process.  Add a separate column to the table.  Parse the memo fields once.  Update the dates and change the interface so you never have to do this again.