Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
Django and microsecond discrepancy in DateTimeField

I have a code that calculates a given datetime as follows

time = datetime.datetime.now() - datetime.timedelta(minutes=60)

I then use time to set a field in an offer object to be saved in the database. The offer.time is a Offer model instance; it is configured to be:

time = models.DateTimeField(blank=True, null=True) 

It happens, however, that offer.time is updated when calling offer.save(). When setting offer.time = time, I get 2017-04-29 09:36:14.895581. After calling offer.save, offer.time is 2017-04-29 09:36:14.895000. Why isn't save() preserving the original time?

Any ideas?

Thanks in advance.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

https://docs.mongodb.com/manual/reference/method/Date/

Internally, Date objects are stored as a 64 bit integer representing the number of milliseconds since the Unix epoch (Jan 1, 1970), which results in a representable date range of about 290 millions years into the past and future.

This explains why 2017-04-29 09:36:14.895581 becomes 2017-04-29 09:36:14.895000

2017-04-29 09:36:14 will be stored as 1493458574000 leaving only 3 more decimals to store milliseconds. When adding milliseconds the value will be 1493458574895. When this is read back into the DateTimeField, the value will be 2017-04-29 09:36:14.895000.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda