Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change time format in Django Views

importdatetime

in my django views to save the time in database

and

now = datetime.datetime.now()

when i am saving its value in database it returns something like

2013-04-28 22:54:30.223113

how can i remove

223113 from 2013-04-28 22:54:30.223113

part please suggest how can i do this ...

like image 872
user2106353 Avatar asked Nov 30 '22 13:11

user2106353


1 Answers

You should ideally be using datetime field in your database. But if there is a constraint that you go to store date as a string use this to format it :

>>> datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 
'2013-04-29 12:17:55'
like image 162
DhruvPathak Avatar answered Dec 02 '22 22:12

DhruvPathak