Cannot filter data by '% V'.

asd = User.query.get(1) print(asd.created_at.strftime('%V')) >>> 07 print('0' + str(int(datetime.now().isocalendar()[1]))) >>> 07 nnnn = User.query.filter(func.strftime('%V', User.created_at) == ('0' + str(datetime.now().isocalendar()[1]))).all() print(nnnn) >>> [] 

For greater certainty, I did a check:

 if asd.created_at.strftime('%V') == ('0' + str(int(datetime.now().isocalendar()[1]))): print('yeah!') 

what do I get

 >>> yeah! 

% V - The current year (01 to 53) of ISO 8601, where it is the first week of the year.

% W - the week number of the first year

However, if I replace '% V' with '% W', then the results do not change (with the print I get 07 and 07 in both cases, since this year% V =% W), and the sample gives the desired result.

What can be wrong ?

Thank you in advance!

  • On my system: SELECT strftime('%V','now'); returns None ( SELECT strftime('%W','now') returns '07' ). At PostgreSQL, you can try: session.query(User).filter(func.to_char(User.created_at, 'IW') == '07') - jfs
  • aside: you can '%02d' % datetime.now().isocalendar()[1] to automatically add zero if necessary. - jfs
  • @jfs, on development I use sqllite3 (which I regret now, due to the inability to drop it), but on postgres production, I can’t check it out. - Narnik Gamarnik

0