How can I get week number from date, in SQL there is a function: Datepart(GetDate()) and this return the number of week. How can I get this in SQLite?
You can use the strftime
function with the format string (1st parameter) as %W
as per SQL As Understood By SQLite - Date And Time Functions.
DROP TABLE IF EXISTS getweek;
CREATE TABLE IF NOT EXISTS getweek (mydate TEXT);
INSERT INTO getweek VALUES ('2018-01-01'),('2018-02-01'),('2018-03-01');
SELECT *, strftime('%W',mydate) AS weekofyear FROM getweek;
Which results in :-
Note The date has to be in one of the recognised date/time formats (e.g. 2018/03/01 would result in null as the date is not in recognised format). See the Time Strings section in the link above for the recognised formats.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加