UserRA
UserRA

Reputation: 185

storing date into mongodb using python in ISO format

I am trying to store date into mongodb using python(bottle framework). I want to store it in the below format:

ISODate("2015-06-08 03:38:28")

Currently I am using the following command:

datetime.strptime(DateField, '%m/%d/%Y %H:%M:%S %p')

it is getting stored like this:

ISODate("2015-06-08T03:38:28Z")

How to store it without "T" and "Z" in it??

Upvotes: 1

Views: 636

Answers (1)

Burhan Khalid
Burhan Khalid

Reputation: 174708

You are confusing how something is stored vs. how something is displayed.

In MongoDB, dates are stored as 64 bit integers, what you are seeing is the way it is represented so that we can easily determine what date and time the 64bit number represents.

The ISODate is just a helper method, which formats the date in the ISO date format.

So when you pass it in a normal date and time string, it will convert it into the correct format.

The format adds the T (to separate the time part) and the Z (as you have not identified a time zone, it is defaulted to UTC).

In short - you are not storing it with the T and the Z, that's just how it is displayed back to you.

Upvotes: 1

Related Questions