-2

I need to extract the week of the month i.e. 1-5 from the date. I am using below formula in python.

df['Week_no_Month']= ((df.DATE.dt.day-1)//7+1) 

Now I want this implemented in SQLite.

Wolf
  • 9,679
  • 7
  • 62
  • 108
Kanika Singhal
  • 253
  • 1
  • 2
  • 10

1 Answers1

1

If you mean that the week is the day divided by 7, then:

select (strftime('%d', dt.day) + 6 / 7)

SQLite is flexible about mixing strings and numbers, so you don't need an explicit conversion -- although you might want to include that:

select (cast(strftime('%d', dt.day) as int) + 6 / 7)
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786