pkm
pkm

Reputation: 2783

Django Auth user date_joined field datetime to string

When i am fetching the stored datetime value from auth user in django the value comes as below is there a way to convert this into normal date time format may be like "dd:mm:yyyy hh:mm:ss" or some string value that can be displayed in better(other) format

 date_joined = request.user.date_joined
 #date_joined value is 
 #datetime.datetime(2016, 9, 11, 16, 6, 22, 314637, tzinfo=<UTC>)

Upvotes: 1

Views: 1407

Answers (1)

Daniel Hepper
Daniel Hepper

Reputation: 29967

You can format a datetime object using its strftime() method, for example like this:

 date_joined = request.user.date_joined
 date_joined.strftime("%d:%m:%y %H:M:S")

If you want to display a datetime object in Django template, you can use the builtin date filter.

{{ date_joined|date:"d:m:Y H:i:s")

Upvotes: 3

Related Questions