Format year on Sqlite

Asked

Viewed 222 times

0

I need to format a timestamp in the following format:

DDMMYYHHMMSS

I got it using the strftime, example:

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

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

2 answers

1

Perhaps the best solution is to treat this directly in the programming language, since the strftime() in the Sqlite does not implement all formatting options of strftime() of language C. But if you can’t 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 kind of confusing.

0

The suggestion of Giovanni It’s interesting, it doesn’t suit you?

I don’t know a way "direct" bring the year with only two characters (e.g. yy or %y), then my suggestion would be to go around it and return a substring of your query. (considering that you must return from comic date in this format, rather than treat it via language):

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.