Comparing two date strings in Python

前端 未结 6 1002
庸人自扰
庸人自扰 2020-11-29 07:56

Let\'s say I have a string: \"10/12/13\" and \"10/15/13\", how can I convert them into date objects so that I can compare the dates? For example to see which date is before

6条回答
  •  野性不改
    2020-11-29 08:34

    If you like to use the dateutil and its parser:

    from dateutil.parser import parse
    
    date1 = parse('10/12/13')
    date2 = parse('10/15/13')
    
    print date1 - date2
    print date2 > date2
    

提交回复
热议问题