In your example, parse('April 19, 2006')
returns a datetime object representing the date and time April 19, 2006 at 00:00:00. This is because the input string 'April 19, 2006' contains a well-formatted date and does not contain any extraneous information that could confuse the parsing algorithm.
However, when you pass the string April 19, 2006 test test
to the parse function, it returns None
because the string contains additional text that is not part of a valid date format.
If you want to parse a string that includes additional text, you can use the dateutil
module instead:
from dateutil import parser
print(parser.parse('April 19, 2006')) # returns 2006-04-19 00:00:00
print(parser.parse('April 19, 2006 test test')) # returns 2006-04-19 00:00:00