2017-11-23 3 views
0

datetime을 유닉스 타임 스탬프로 변환하려고합니다. 몇 가지 방법을 시도하고 오류가 모두 동일합니다. 나는 내가 무엇을하기로되어 있는지 잘 모른다.function UNIX_TIMESTAMP가 없습니다.

date_joined는 포스트 그레스는 (see here) 그렇게 못하게하기 때문이다이 2017-09-30 10:24:44.954981+00:00

function unix_timestamp(timestamp with time zone) does not exist 
HINT: No function matches the given name and argument types. You might need to add explicit type casts. 


User.objects.annotate(photo_time=Func(F('date_joined'),function='UNIX_TIMESTAMP')) 
User.objects.extra(select={'photo_time':"to_unixtime(date_joined)"}) 
#also tried and UNIX_TIMESTAMP 

답변

1

같다. 당신이 정말로 UNIX_TIMESTAMP이 필요하지 않은 경우, 당신은 Extract

User.objects.annotate(photo_time=Extract('date_joined', 'epoch').get()) 

은 물론, 당신은 또한 TO_UNIXTIME 저장 프로 시저/함수를 정의 할 수 필요하지만, 그 맨 위에 조금 보인다.

관련 문제