Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 772017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:44:42+00:00 2026-05-14T18:44:42+00:00

I use django, and have two models with a models.DateTimeField(). Sometimes I need a

  • 0

I use django, and have two models with a models.DateTimeField(). Sometimes I need a copy of a date – but look at this:

>>>myobject.date = datetime.datetime.now()
>>>print myobject.date
>>>2010-04-27 12:10:43.526277

>>>other_object.date_copy = myobject.date
>>>print other_object.date_copy
>>>2010-04-27 12:10:43

Why are these two dates not identical, and how do I make an excact copy of myobject.date?

Edit:

I made the mistake of oversimplifying the code I used. The following code will replicate the weirdness:

>>>myobject.date = datetime.datetime.now()
>>>print myobject.date
>>>2010-04-27 12:10:43.526277
>>>myobject.save()
>>>myobject_retrieved_from_db = Myobject.objects.get(id=myobject.id) 

>>>other_object.date_copy = myobject_retrieved_from_db.date
>>>print other_object.date_copy
>>>2010-04-27 12:10:43

As Petriborg suggested, the difference in time is caused by storing to the database:

>>>print myobject_retrieved_from_db.date
>>>2010-04-27 12:10:43

Mystery solved.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:44:43+00:00Added an answer on May 14, 2026 at 6:44 pm

    What version of python are you using?

    Seems to work for me…

    In [3]: s = datetime.datetime.now()
    In [4]: x = s
    In [5]: print s
    ------> print(s)
    2010-04-27 06:37:02.303067
    In [6]: print x
    ------> print(x)
    2010-04-27 06:37:02.303067
    

    Are you storing the datetime into a 3rd party structure like an sqldb via django? A time struct is usually of the form { int seconds; int fractional_seconds; } or as a long milliseconds, so it might be that the second part is getting dropped, either by structure, or by down casting…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models in my Django application, for the purposes of storing search
I have two models in Django: groups and entries. Groups has a many-to-many field
I have the following two models class Author(Model): name = CharField() class Publication(Model): title
I have two models in relation one-to-many: class Question(db.Model): questionText = db.StringProperty(multiline=False) class Answer(db.Model):
I have two models: Play and PlayParticipant , defined (in part) as: class PlayParticipant(models.Model):
I have two models: class Actor(models.Model): name = models.CharField(max_length=30, unique = True) event =
I've run into a problem with using two models for my form in Django.
Hello (please excuse me for my ugly english :p), Imagine these two simple models
I was wondering if the following migration is possible with Django south and still

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.