代码之家  ›  专栏  ›  技术社区  ›  Luv33preet

postgres server和excel中的时间不同

  •  0
  • Luv33preet  · 技术社区  · 8 年前

    我正在尝试按月份对数据进行分组的查询。

    test_db=# select date_trunc('month', install_ts) AS month, count(id) AS count from api_booking group by month order by month asc;         
     month                  | count 
    ------------------------+-------
     2016-08-01 00:00:00+00 |   297
     2016-09-01 00:00:00+00 |  2409
     2016-10-01 00:00:00+00 |  2429
     2016-11-01 00:00:00+00 |  3512
    (4 rows)
    

    这是我的postgres db shell中的输出。

    然而,当我在excel中尝试此查询时,这是输出,

     month                  | count 
    ------------------------+-------
     2016-07-31 17:00:00+00 |   297
     2016-08-31 17:00:00+00 |  2409
     2016-09-30 17:00:00+00 |  2429
     2016-10-31 17:00:00+00 |  3512
    (4 rows)
    

    问题是,我认为excel理解不同时区的日期格式。 那么,如何让excel正确阅读呢? 或者这个问题有什么解决方案?

    1 回复  |  直到 8 年前
        1
  •  1
  •   carrot    8 年前

    尝试

    select date(date_trunc('month', install_ts)) AS month, count(id) AS count from api_booking 
    

    date()用时间从日期中去掉时间。