I’m trying to get a single datetime out of two strings using datetime.strptime.
The time is pretty easy (ex. 8:53PM), so I can do something like:
theTime = datetime.strptime(givenTime, "%I:%M%p")
However, the string has more than just a date, it’s a link in a format similar to http://site.com/?year=2011&month=10&day=5&hour=11. I know that I could do something like:
theDate = datetime.strptime(givenURL, "http://site.com/?year=%Y&month=%m&day=%d&hour=%H")
but I don’t want to get that hour from the link since it’s being retrieved elsewhere. Is there a way to put a dummy symbol (like %x or something) to serve as a flexible space for that last variable?
In the end, I envision having a single line similar to:
theDateTime = datetime.strptime(givenURL + givenTime, ""http://site.com/?year=%Y&month=%m&day=%d&hour=%x%I:%M%p")
(although, obviously, the %x wouldn’t be used). Any ideas?
Think that if you would like to simple skip time from the URL you can use split for example the following way:
So not sure that understood you correctly, but: