Martin Kóňa
Martin Kóňa

Reputation: 151

Extract year and month from timestamp(6)

I have database, where i have inserted timestamps(6) in this format : 18-AUG-14 02.49.27.000000000 PM .

I want to extract it into this: 2014-08

Its called ISO 8601

Upvotes: 4

Views: 50627

Answers (2)

iSaumya
iSaumya

Reputation: 1623

I've done this in this way -

select extract(year from timestmp) || '-' || extract(month from timestmp) from texmp1;

Hope this helps.

Here is the table structure:

    create table texmp1 
(
timestmp timestamp
);

Upvotes: 0

Sathyajith Bhat
Sathyajith Bhat

Reputation: 21851

You'll need to use the to_char function to extract the year-month from timestamp.

select to_char(timestamp, 'yyyy-mm') from your_table

Upvotes: 9

Related Questions