Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda