Theo Katsumi
Theo Katsumi

Reputation: 5

Format datestring dd/mm/yyyy to yyyy-mm-dd

The user input the date as DD/MM/YYYY and sqlite needs to convert it to YYYY-MM-DD.

How can i do that?

Tested that i done:

    strftime("%Y-%m-%d", "03/01/2000")

Upvotes: 0

Views: 787

Answers (1)

forpas
forpas

Reputation: 164099

The function strftime() does not help in this case.
You have to use substr() and concatenation:

substr('03/01/2000', 7) || '-' || substr('03/01/2000', 4, 2) || '-' || substr('03/01/2000', 1, 2)

Result:

2000-01-03

Note: If you plan to store dates with SQLite, store them in the format YYYY-MM-DD.
It is comparable and for it you can use strftime() to format it anyway you want.

Upvotes: 1

Related Questions