954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

sql to get year only

hi all. below is my code. what i want is the financial_year_end to return only year instead of yyyy-mm-dd format. can anyone show me how can i do that? many thanks in return :)

SELECT a.stock_code, a.financial_year_end, current_name, board_name, sector_name, sub_sector_name, e.year_id, (receivable*365/revenue) AS "totaldso"
FROM qiddb.company_info a
LEFT JOIN ref_board b ON (b.board_code=a.board_code)
LEFT JOIN ref_sector c ON (c.sector_code=a.sector_code)
LEFT JOIN ref_sub_sector d ON (d.sub_sector_code=a.sub_sector_code)
LEFT JOIN company_financial e ON(e.stock_code=a.stock_code)
WHERE b.board_code='am' AND e.year_id = '2009'
violette
Junior Poster in Training
63 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

Maybe you can try

Select str_to_date(financial_year_end , '%Y') from tableName


http://www.java2s.com/Tutorial/MySQL/0280__Date-Time-Functions/STRTODATEstrformat.htm
here is the web site for your reference

Hope this help :)

BlurrieBlue
Light Poster
43 posts since Sep 2011
Reputation Points: 10
Solved Threads: 4
 

thank you BlurrieBlue for the reference. :)

violette
Junior Poster in Training
63 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

i've found easier solution to get ,year or month from a date.

SELECT YEAR(financial_year_end)
FROM company_info


with this code, it will return only year of the date.

violette
Junior Poster in Training
63 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You