?
Solved

MS Access extract date

Posted on 2012-09-07
4
Medium Priority
?
965 Views
Last Modified: 2012-09-08
Hi,

I'm having a little bit of difficulty trying to extract a date out of some fields because the format changes slightly on every record.
The fields are like:
Dec 5 (0.5hr)
Dec 5, 12 (0.5hr)
Sept 8
March 10, (.75hr)
January 7, 15 (1hr)

I have this so far:
        comma_exists = InStr(1, ItemLineDesc, ",")

        If (comma_exists > 0) Then
            first_date = Left(ItemLineDesc, InStr(1, ItemLineDesc, ","))
        Else
            first_date = Left(ItemLineDesc, InStr(4, ItemLineDesc, " "))
        End If

But with the comma I still have the comma at the end for the variable first_date when there is a comma.

I basically just need the date. Any help is appreciated.

Thanks,
vkimura
0
Comment
Question by:Victor Kimura
  • 2
4 Comments
 
LVL 52

Assisted Solution

by:Gustav Brock
Gustav Brock earned 400 total points
ID: 38378093
You could use:

ItemLineDesc = Replace(ItemLineDesc, ",", "")

to first filter out the comma.

/gustav
0
 
LVL 61

Accepted Solution

by:
mbizup earned 1600 total points
ID: 38378110
You could also use this one-liner for the whole thing:

replace(split(ItemLineDesc," ")(0) & " " &  split(ItemLineDesc," ")(1),",","")
0
 

Author Closing Comment

by:Victor Kimura
ID: 38378149
mbizup, that's awesome! In one line!

Thanks, cactus_data
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 38378893
You are welcome!

/gustav
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question