i've a date column stored in a table... the format is 2004-06-30 (Y-m-d)
...
now, i want to retrieve it from the database and display only the year...
for example... if the date stored is 2004-06-30, then it should return 2004...
what query should i use? i've try to_date... they came out error...
how can i do that?
tq~
[SOLVED] display only year from a full format date...
Moderator: General Moderators
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
Code: Select all
substr($row['date'],0,4);
Last edited by Illusionist on Wed Jun 23, 2004 11:56 pm, edited 1 time in total.
Code: Select all
select year(yourdatecolumn) as `year` from yourtable....Or you could do it in the query part, eg:
SELECT EXTRACT(YEAR FROM '1999-07-02'); would get '1999' more examples here
SELECT EXTRACT(YEAR FROM '1999-07-02'); would get '1999' more examples here
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
another way!!!
Code: Select all
$array = explode('-', '2004-06-30');
echo $array[0];