3

Problem: When I print time in my HTML code it shows like this: 2020-05-31 03:29:50.617897

Code: https://i.stack.imgur.com/HTIXy.png

Question: How to get rid of decimal .617897? Thank you. I'm new to programming.

Bruce Salcedo
  • 167
  • 1
  • 7
  • Search StackOverflow for "[python] round time to seconds" or "[python] format time string" or "[python] format time (in that framework your are using that accepts {{ time }} in HTML)". – user2864740 May 30 '20 at 20:07
  • 1
    There probably is not much of a reason to drag SQL into this, unless explicitly wishing to do the operation before the result is returned to Python; in part, this is because one still might want to control the output formatting anyway. – user2864740 May 30 '20 at 20:10
  • I searched for it but i still cant get a hold of it. :( im using jinja as for my framework btw. – Bruce Salcedo May 30 '20 at 20:20
  • See https://stackoverflow.com/q/4830535/2864740 , https://stackoverflow.com/q/12681036/2864740 via "python jinja format time"; and [formatting for strfime](https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior) via "python strftime". – user2864740 May 30 '20 at 20:23
  • 1
    So be welcome! Please note that per SO rules, your question should include all the relevant code, **as text**. It would make it really better and would avoid downvotes/closure... – Thierry Lathuille May 30 '20 at 21:02

2 Answers2

5

In Postgres, you can use date_trunc():

select date_trunc('second', current_timestamp)
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
3

Like this?

a = '2020-05-31 03:29:50.617897'
a = a.split('.')[0]
print(a)

Output:

'2020-05-31 03:29:50'
Red
  • 26,798
  • 7
  • 36
  • 58