Fabian
Fabian

Reputation: 127

Oracle SQL: selecting date field without day (Only Month and Year)

I need to select values from a Database where I have a complete Date. Now I have to get this Date without the Day because I have to group and count them per Month.

I did it like this, but this will get me the Month like for January with 1 and I need 01...

(extract(YEAR,Month from ak.date ) || '.' ||extract(Month from ak.date) ) as Datum

Upvotes: 5

Views: 11447

Answers (2)

Jeffrey Kemp
Jeffrey Kemp

Reputation: 60262

Another way:

TRUNC(ak.date, 'MM')

Advantage of this is that date sorting and date arithmetic still work.

Upvotes: 1

Ed Gibbs
Ed Gibbs

Reputation: 26333

Use the TO_CHAR function for this:

TO_CHAR(ak.date, 'YYYY.MM') as Datum

Upvotes: 8

Related Questions