如何从DATE中提取小时,分钟和秒

时间:2016-04-25 20:41:10

标签: sql postgresql

我有以下查询:

select cast(max_bid_ts as TIMESTAMP) from my_table;

我投了max_bid_ts,因为它是双倍的,我想成为TMESTAMP。此查询返回类似此内容的

2016-04-21 12:41:46.313999872

我只想要小时:分:秒部分。在这种情况下将是12:41:46。最好的方法是什么?

2 个答案:

答案 0 :(得分:5)

尝试这样的事情:

select YourTimeStampField::time from YourTable

如果你想要一个24小时的时间格式,试试这个:

{
"graphset":[
  {
      "type":"bar",
      "plotarea":{
        "adjust-layout":true,
        "mask-tolerance":[0,0]
      },
      "background-color":"#fff",
      "plot":{
          "alpha":0.9,
          "border-width":1,
          "border-color":"black",
          "cursor":"pointer",
          "border-radius-top-left":4,
          "border-radius-top-right":4,
          "animation":{
              "effect":"ANIMATION_SLIDE_BOTTOM"
          },
          "hover-state":{
              "alpha":1,
              "visible":true
          },                
          valueBox:{},
          tooltip:{
              "border-color":"#fff",
              "border-width":1,
              "border-radius":3,
              "wrap-text":true,
              "alpha":0.8,
              "text":"%node-value % chances in %data-timespan Days for location %kl"
          }
      },
      "scale-x":{
          "zooming":true,
          "label":{
              "text":"Location",
              "font-color":"#000",
              "font-size":"16px",
              "text-align":"center",
              "background-color":"#fff",
              paddingTop:20
          },
          "values":[" HYDERABAD"," GURGAON"," JAIPUR"],
          "line-color":"#CCC",
          "tick":{
              "visible":false
          },
          "guide":{
              "line-color":"#666",
              "line-style":"solid"
          },
          "item":{
              "font-family":"arial",
              "font-color":"#000",
              "background-color":"rgb(255,255,255)",
              "padding-top":"4px"
          }
      },
      "scale-y":{
          "zooming":true,
          "label":{
              "text":"Attrition Rate",
              "font-color":"#2B776C",
              "font-size":"16px"
          },
          "line-color":"#CCC",
          "tick":{
              "visible":false
          },
          "guide":{
              "line-style":"dashed",
              "line-color":"#ccc"
          },
          "item":{
              "font-family":"arial",
              "font-color":"#8B8B8B"
          },
          "zoom-to":[32.5,34.5]
      },
      "series":[
          {
              "values":[33.59,33.36,32.93],
              "background-color":"#ff3b3b",
              "line-color":"#ff3b3b",
              'data-timespan':30
          },
          {
              "values":[33.5,33.08,32.93],
              "background-color":"#ff9b67",
              "line-color":"#ff9b67",
              'data-timespan':30
          },
          {
              "values":[32.91,33.55,34.15],
              "background-color":"#6cebb3",
              "line-color":"#6cebb3",
              'data-timespan':30
          },
          {
              "values":[32.78,33.33,33.78],
              "background-color":"#ff3b3b",
              "line-color":"#ff3b3b",
              'data-timespan':60
          },
          {
              "values":[34.04,33.63,32.93],
              "background-color":"#ff9b67",
              "line-color":"#ff9b67",
              'data-timespan':60
          },
          {
              "values":[33.19,33.04,33.29],
              "background-color":"#6cebb3",
              "line-color":"#6cebb3",
              'data-timespan':60
          },
          {
              "values":[33.76,32.58,33.51],
              "background-color":"#ff3b3b",
              "line-color":"#ff3b3b",
              'data-timespan':90
          },
          {
              "values":[32.76,33.98,33.78],
              "background-color":"#ff9b67",
              "line-color":"#ff9b67",
              'data-timespan':90
          },
          {
              "values":[33.49,33.43,32.71],
              "background-color":"#6cebb3",
              "line-color":"#6cebb3",
              'data-timespan':90
          }
      ]
  }

另一种方式是:

{{1}}

答案 1 :(得分:0)

select to_char(sysdate,'HH:MM:SS') from dual;