Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

DateTime Python

By
kais dkhili
on 8/14/14, 11:05 AM 7,348 views

Hello,
i'm newest on Python, i want to convert this value  2014-08-14 16:35:38.159891 to this value  2014-08-14 16:35:38, i mean that i want that the format of the date like the following
aaaa-mm-dd hh:mm:ss

4
David Durá Vilches
On 8/14/14, 11:24 AM

This is what we can do with the datetime and time modules in Python

import time

import datetime

print "Time in seconds since the epoch: %s" %time.time()

print "Current date and time: " , datetime.datetime.now()

print "Or like this: " ,datetime.datetime.now().strftime("%y-%m-%d-%H-%M")

print "Current year: ", datetime.date.today().strftime("%Y")

print "Month of year: ", datetime.date.today().strftime("%B")

print "Week number of the year: ", datetime.date.today().strftime("%W")

print "Weekday of the week: ", datetime.date.today().strftime("%w")

print "Day of year: ", datetime.date.today().strftime("%j")

print "Day of the month : ", datetime.date.today().strftime("%d")

print "Day of week: ", datetime.date.today().strftime("%A")

            That will print out something like this:

Time in seconds since the epoch: 1349271346.46

Current date and time: 2012-10-03 15:35:46.461491

Or like this: 12-10-03-15-35

Current year: 2012

Month of year: October

Week number of the year: 40

Weekday of the week: 3

Day of year: 277

Day of the month : 03

Day of week: Wednesday

 

 

 

Try: 

datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

Try: datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") I think is wha you want...

David Durá Vilches
on 8/14/14, 11:46 AM
0
kais dkhili
On 8/14/14, 11:31 AM

Thanx David for your answer your answer but i want that Current date and time takes only this value, 2012-10-03 15:35:46

0
Anand
On 11/17/14, 12:04 AM

from datetime import datetime

current_date=str(datetime.now().date())

d2=datetime.strptime(current_date, "%Y-%m-%d")

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 8/14/14, 11:05 AM
Seen: 7348 times
Last updated: 9/1/16, 10:37 PM