osterburg
osterburg

Reputation: 447

How to find and remove datetime in string, ie: Sun Mar 3, 2019 07:39AM

I have a large text file which contains dates similar to

Sun Mar 3, 2019 07:39AM

and was wondering if there is a good way to search and remove it from the text. AM/PM could also be lowercase and may have a space in front.

Thanks

Upvotes: 2

Views: 50

Answers (2)

Sridhar Murali
Sridhar Murali

Reputation: 380

If you are not comfortable with regex you could try this:

'Sun Mar 3, 2019 07:39AM'.split()[-1].lower()

Output:

'07:39am'

I have assumed that the example you have given is a string and a uniform format is used through out your dataset.

Upvotes: -1

Scott Hunter
Scott Hunter

Reputation: 49803

If you know the format, you could use regex to locate the dates and then strptime if you need to get the date's value.

Upvotes: 3

Related Questions