Converting date between DD/MM/YYYY and YYYY-MM-DD?

前端 未结 6 1967
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 16:24

Using a Python script, I need to read a CVS file where dates are formated as DD/MM/YYYY, and convert them to YYYY-MM-DD before saving this into a SQLite database.

Th

6条回答
  •  -上瘾入骨i
    2020-12-23 16:58

    you first would need to convert string into datetime tuple, and then convert that datetime tuple to string, it would go like this:

    lastconnection = datetime.strptime("21/12/2008", "%d/%m/%Y").strftime('%Y-%m-%d')
    

提交回复
热议问题