Friday 15 July 2011

python - Error while comparing dates in different formats -


I get the following error when the codenippet is executing below, I created "DueDate" and "Date", what This is because both of them are in different time formats? How to convert to "Date Created" as "vs Date"

Error: -

 < Code> Type Error: - 'Text' and 'datetime.datetime'  

Code SNIPPET: -

  If ((none!): Unsupported operation type (s) = DueDate) and (DueDate - CreatedDate) .days & lt; 1)):  

Sample Input: -

  Due Date 2/6/2015 Created Date 2015 -02-03 20: 15: 47.950000  

You need to change your date The string for the datetime object. There is no underlying conversion in the string from the datetime object. You can try something like the following.

  Import date time = "3/17/2015" # I used place instead of now to create your datetime object Gone Datetime_object = datetime.datetime.now () due_date = datetime.datetime.strptime (date, "% m /% d /% Y") If set_data! = None and (datetime_object - due_date). Day & lt; 1: print ("clever messaging")  

edit

Thanks for comment by @JFSBeeton I time.strptime . See the comments below for details.


No comments:

Post a Comment