Format date as day of week

前端 未结 3 1779
滥情空心
滥情空心 2020-12-05 11:55

I have a table which has amongst others a date column servdate.

I use the following query to get me all jobs from within the past week ( a week starts f

3条回答
  •  醉话见心
    2020-12-05 12:11

    SELECT _id, busnum, date_format(servdate, '%a') as servdayofweek
    FROM tb1
    WHERE servdate BETWEEN date('now', 'Weekday 1', '-21 days') AND date('now')
    

    The %a is the abbreviated day of the week. See the documentation for other ways to format.


    edit:

    Oops! Overlooked the sqlite tag. The above is for MySQL. For sqlite (documentation):

    SELECT _id, busnum, strftime('%w', servdate) as servdayofweek
    FROM tb1
    WHERE servdate BETWEEN date('now', 'Weekday 1', '-21 days') AND date('now')
    

    except this returns the day of week as a value 0 through 6. Maybe that's good enough?

提交回复
热议问题