Solved

find a string pattern and then extract date from it

Posted on 2009-04-02
3
230 Views
Last Modified: 2013-11-25
if have a array of strings.
some of them look like:

test1
test2

but others look like
"2006-06 (jun)"
"2006-07 (jul)"

now i want to extract the date part from these strings (only the one's which contain the date, e.g. 2006-06) and convert (only the strings which look like they have date in them)  them to a "date time" format and store them in another array as "date time" items

how do i do it?

how


0
Comment
Question by:manivineet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Expert Comment

by:Avelan
ID: 24057143
Hey,
this should work.
Other solution is to use regex to extract the date but i'm not too familiar with it
so... ;)

-Avelan
MyStr = Split(str, " ")(0)
 
If IsDate(str) Then
   MyDate = Date.Parse(str)
   'Whatever else you need to do
Else
    'whatever
End If

Open in new window

0
 
LVL 4

Accepted Solution

by:
Avelan earned 500 total points
ID: 24057148
Whoops, a couple mistakes there but i'm sure you caught them anyhow :P
MyStr = Split(str, " ")(0)
 
If IsDate(MyStr) Then
   MyDate = Date.Parse(MyStr)
   'Whatever else you need to do
Else
    'whatever
End If

Open in new window

0
 
LVL 9

Expert Comment

by:Deathrace
ID: 24057703
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

739 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