3

I have the following code that extracts a postgres CURRENT_TIMESTAMP from a database

cursor.execute("SELECT submitdate FROM journeys WHERE display = true")
submitDate = cursor.fetchone()['submitdate']

which returns

2015-08-11 12:44:31.790462

How would I format this to show as 11-08-2015 for example?

I've read about and tried things such as this but they don't work

print(
    datetime.datetime.fromtimestamp(
        int("1284101485")
    ).strftime('%Y-%m-%d %H:%M:%S')
)
2
  • 1
    submitDate.strftime("%d-%m-%y") Commented Aug 11, 2015 at 14:06
  • 1
    He wants 11-08-2015 then it shoud be submitDate.strftime("%d-%m-%Y") Commented Aug 11, 2015 at 14:15

1 Answer 1

2

The solution that worked comes from Abhis's comment above.

submitDate.strftime("%d-%m-%Y")
Sign up to request clarification or add additional context in comments.

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.