How to retrieve the Date part out of a Datetime result column in SQLite?

前端 未结 4 1956
被撕碎了的回忆
被撕碎了的回忆 2021-01-03 08:06

I have a column of datetime type from which I would like to retrieve only the date. Is there anyway to do this?

Previously it was an epoch value where I convert it t

4条回答
  •  有刺的猬
    2021-01-03 08:35

    This works.

    SELECT strftime('%d', '2011-04-26')
    

    You can get year, month, day and everything else that is a part of date.

    But you must be carefull how you enter those strings.

    The format of date is YYYY-MM-DD, so you must enter the string in that format.

    It's also case-sensitive. If you want a month, then you should use %m, because if you use %M, it will try to get a minutes, and if you don't have time part in your date, it will throw an error.

    For additional information check SQLite official site.

提交回复
热议问题