views:

28

answers:

1

Hi All ,,

Is there any way to get the get the specific values from date such as year , month , day . Actually we have in php date function . If we give date (Y-m ) ; it will give us 2010-07 . I want like this in postgres(psql) .

Thanks in Advance...

+2  A: 

SELECT to_char(CURRENT_DATE, 'MM') FROM v_use_doc_line ;

This will provide you with the month value of the CURRENT_DATE. If you need year, just replace MM with YYYY.

I hope you can guess now what you should do to get the day :).

For further information, see the to_char function of postgresql.

Night Shade
And link to the manual: http://www.postgresql.org/docs/8.4/interactive/functions-formatting.html
Frank Heikens
@Frank: Thank you, I have added the link..:)
Night Shade
Actually I want both month and year, what I should do....?
pavun_cool
Use YYYY and MM: SELECT to_char(CURRENT_DATE, 'YYYY MM');
Frank Heikens
Yes, It works fine... Thank you so much ....
pavun_cool