Bilgin Kılıç
Bilgin Kılıç

Reputation: 9129

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

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

Upvotes: 31

Views: 85845

Answers (6)

westman379
westman379

Reputation: 723

Here is a good example:

select trunc(to_date('15.11.2019', 'DD.MM.YYYY'), 'MONTH') from dual;

Upvotes: 0

Ashish4434
Ashish4434

Reputation: 118

try this one


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

Upvotes: 3

Erwin Brandstetter
Erwin Brandstetter

Reputation: 658917

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

Upvotes: 2

schurik
schurik

Reputation: 7928

select trunc(sysdate, 'mm') from dual;

Upvotes: 9

BQ.
BQ.

Reputation: 9423

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>

Upvotes: 9

MatBailie
MatBailie

Reputation: 86798

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

SELECT TRUNC(yourDateField, 'MONTH') FROM yourTable

Upvotes: 60

Related Questions