How to remove unconverted data from a Python datetime object -


i have database of correct datetimes few broke so: sat dec 22 12:34:08 pst 20102015

without invalid year, working me:

end_date = soup('tr')[4].contents[1].rendercontents() end_date = time.strptime(end_date,"%a %b %d %h:%m:%s %z %y") end_date = datetime.fromtimestamp(time.mktime(end_date)) 

but once hit object invalid year valueerror: unconverted data remains: 2, great im not sure how best strip bad characters out of year. range 2 6 unconverted characters.

any pointers? slice end_date im hoping there datetime-safe strategy.

yeah, i'd chop off numbers. assuming appended datestring, work:

end_date = end_date.split(" ") end_date[-1] = end_date[-1][:4] end_date = " ".join(end_date) 

i going try number of excess digits exception, on installed versions of python (2.6.6 , 3.1.2) information isn't there; says data not match format. of course, continue lopping off digits 1 @ time , re-parsing until don't exception.

you write regex match valid dates, including right number of digits in year, seems overkill.


Comments

Popular posts from this blog

jQuery clickable div with working mailto link inside -

java - Getting corefrences with Standard corenlp package -

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -