Format year in SQLite

0

I need to format a timestamp in the following format:

DDMMYYHHMMSS

I was able to use strftime , for example:

select strftime("%d%m%Y%H%M%S", current_timestamp) from stream;

But this way it shows 4 digits for the year and I only need the last two, how to format since %y is not valid.

    
asked by anonymous 30.03.2018 / 21:00

2 answers

1

Perhaps the best solution is to treat this directly in the programming language, since strftime () in SQLite does not implement all strftime formatting options () of the C language. But if you can not do it the solution is to run the function twice, cut and concatenate:

select strftime('%d%m', current_timestamp)||substr(strftime("%Y%H%M%S", current_timestamp),3);
300318195604

But the end result is a bit confusing.

    
30.03.2018 / 21:59
0

The suggestion of the response of Giovanni is interesting, does not it serve you?

I do not know a "direct" way to bring the year with only two characters (ex yy or %y ), so my suggestion would be to get around this and return a substring of your query. (assuming you need to return from bd with the date in this format, rather than treating it via language):

select substr(strftime("%d%m%Y%H%M%S", current_timestamp), 3) from stream;
    
05.04.2018 / 13:38