Shortest way to compare 2 dates in dd/mm/yyyy format

后端 未结 7 1383
轻奢々
轻奢々 2021-01-20 23:44

can anyone suggest the neatest way to do this comparison? I need to test if a date provided in dd/mm/yyyy format is less than a fixed date, e.g 01/05/2009 - I know I can convert

7条回答
  •  野性不改
    2021-01-21 00:27

    One option is just to reverse the format - create a string of the form

    yyyy/mm/dd
    

    That's a sortable format, so you can just do an ordinal string comparison. Of course, this means you won't detect invalid data etc.

提交回复
热议问题