0

I have the following model class

class Transaction(models.Model):
    quantity = models.IntegerField(default=0)
    sell_time = models.DateTimeField()

When I fetch "sell_time" from the model, I am getting datetime in the following format

2014-10-01 08:09:46.251563+00:00

my question is, if it is not in the format like

year-month-day hour:minutes:seconds

how can I convert to python datetime object like

datetime.datetime(2014, 10, 1, 08, 09, 46, 540535)

many thanks

2 Answers 2

1

Did you print it? If you print a datetime object, it is serialized to a string but it is a datetime. You can use it as any other datetime.

Sign up to request clarification or add additional context in comments.

4 Comments

My doubt behind the question is I never made a sell at 2014-10-01 8am.
It's 8am GMT, that might be any other time depending on the time zone you are in.
is ther any module for converting gmt to ist in python?
0

You are seeing that because you did not set the correct time zone. Use the UTC time and then you can format .strftime("format") the time accordingly to each locale, you can install pytz and enable it in the settings to handle all the hustle. Always use UTC datetime object because then you can get what ever time you want knowing the zone your user is in. Documentation from Django

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.