How to extract hour from query in postgres

后端 未结 3 1405
后悔当初
后悔当初 2021-01-17 07:28

I have timestamp in my table and i want to extract only hour from it. I search and find a extract function but unable to use as a query. Do i need to convert first timestamp

相关标签:
3条回答
  • 2021-01-17 07:45

    The word timezone is redundant (read: wrong). You just need to give the column's name. E.g.:

    db=> select extract(hour from observationtime) from smartvakt_device_report;
    
     date_part 
    -----------
            19
    (1 row)
    
    0 讨论(0)
  • 2021-01-17 07:57

    The following should work

    select extract(hour from observationtime) from smartvakt_device_report
    
    0 讨论(0)
  • 2021-01-17 08:02
    SELECT to_char(now(), 'HH24:MI:SS')  hour_minute_second
    
    0 讨论(0)
提交回复
热议问题