Oracle, Make date time's first day of its month

前端 未结 6 491
后悔当初
后悔当初 2020-12-30 21:48

I have a datevariable, I would like to have convert it to first day of its monh,

  • Eg: 10/10/2010 -> 01/10/2010
  • Eg: 31/07/2010 -> 01/07/2010
相关标签:
6条回答
  • 2020-12-30 21:53
    SELECT trunc(to_date('22-AUG-03'), 'MON') FROM dual;
    

    More in the manual.
    About Oracle needing a dummy FROM: Select without a FROM clause in Oracle

    0 讨论(0)
  • 2020-12-30 21:57

    try this one

    
    select trunc(sysdate, 'MM')firstday , trunc(last_DAY(sysdate)) lastday from dual;

    0 讨论(0)
  • 2020-12-30 22:01

    Here is a good example:

    select trunc(to_date('15.11.2019', 'DD.MM.YYYY'), 'MONTH') from dual;
    
    0 讨论(0)
  • 2020-12-30 22:09
    SQL> select to_date('31/07/2010', 'DD/MM/YYYY') from dual;
    
    TO_DATE('
    ---------
    31-JUL-10
    
    SQL> select trunc(to_date('31/07/2010', 'DD/MM/YYYY'), 'MM') from dual;
    
    TRUNC(TO_
    ---------
    01-JUL-10
    
    SQL>
    
    0 讨论(0)
  • 2020-12-30 22:15

    According to http://psoug.org/reference/date_func.html, this should work a dandy...

    SELECT TRUNC(yourDateField, 'MONTH') FROM yourTable
    
    0 讨论(0)
  • 2020-12-30 22:17
    select trunc(sysdate, 'mm') from dual;
    
    0 讨论(0)
提交回复
热议问题