【问题标题】:Reset the date portion to the last of the month while preserving the time将日期部分重置为月的最后一天,同时保留时间
【发布时间】:2018-04-09 19:42:48
【问题描述】:

有什么方法可以在保留时间的同时将日期部分重置为当月的最后一天?例如:

2018-01-02 23:00:00 -> 2018-01-31 23:00:00
2018-04-04 10:00:00 -> 2018-04-30 10:00:00

【问题讨论】:

    标签: sql oracle


    【解决方案1】:

    Oracle 函数last_day() 正是这样做的。试试:

    select last_day(sysdate), sysdate
    from dual
    

    看看它是如何工作的。

    具有讽刺意味的是,我通常认为保留日期是违反直觉的,所以我通常的用法更像是:

    select last_day(trunc(sysdate))
    from dual
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-12
      • 1970-01-01
      • 2011-06-06
      • 2016-01-17
      • 2013-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多