Jump to content

How to find date within a string?


python72

Recommended Posts

I have another question related to string searches.

What I have is a string of couple thousand characters of all types but the date format is allways the same: dd-mth-year (two digits for day-three letters for month-four digits for year). Can I use the format alone to determine where the date is located which in turn would make it very easy to store that date into variables for inserting into database, etc.

Is there anyway to tell php the format to look for or do I have to have actual numbers/letters to perform the search?

 

Link to comment
https://forums.phpfreaks.com/topic/220427-how-to-find-date-within-a-string/
Share on other sites

You can use regular expressions. Just keep in mind that what you get out won't be any better than what you put in.

var_dump(preg_match_all('/\d\d-[a-z][a-z][a-z]-\d\d\d\d/i', $text));

What I mean by that is that it would be a Good Idea to be more specific than "three letters" for the month. List the possibilities out.

(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)

One more pattern question which just came up and the way I am trying to do it is not working.

If the date is in the following format: December 04, 2010 I have to came up with different pattern, I thought that the following pattern would work:

$Pattern='/(January|February|March|April|May|June|July|August|September|October|November|December) \d\d, \d\d\d\d/i';

but it does not work, not sure how to fix it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.