Mahesh Uligade
Mahesh Uligade

Reputation: 627

Convert SQLite query date format

There is a date column in my SQLite databse table, I inserted date in format YYYY-MM-DD for making sorting easy, now I am trying to retrieve date after sorting in Format of DD-MM-YYYY , don't know how do it. Can I do it using SQLite query only and not using displaying language such as PHP or Java

Upvotes: 0

Views: 607

Answers (1)

Michael A. Schaffrath
Michael A. Schaffrath

Reputation: 2110

https://sqlite.org/lang_datefunc.html

The strftime() routine returns the date formatted according to the format string specified as the first argument. The format string supports the most common substitutions found in the strftime() function from the standard C library plus two new substitutions, %f and %J. The following is a complete list of valid strftime() substitutions:

%d day of month: 00
%f fractional seconds: SS.SSS
%H hour: 00-24
%j day of year: 001-366
%J Julian day number
%m month: 01-12
%M minute: 00-59
%s seconds since 1970-01-01
%S seconds: 00-59
%w day of week 0-6 with Sunday==0
%W week of year: 00-53
%Y year: 0000-9999
%% %

-> SELECT strftime('%d-%m-%Y', SELECT date FROM your_table)

Upvotes: 4

Related Questions