Skip to content

DjangoでDateTime フィールド同士をフォーマットを指定して比較する

Posted on:2019年2月7日 at 00:00

概要

SQL では、 DATE_FORMAT(entry_time, '%Y%m%d') と書くところを、Django の queryse でも指定したい

where (DATE_FORMAT(entry_time, '%Y%m%d') = DATE_FORMAT(update_time, '%Y%m%d'))

コード

queryset.extra(where=["DATE_FORMAT(entry_time, '%%Y%%m%%d') != DATE_FORMAT(update_time, '%%Y%%m%%d')",])

参考