I have a db with a column including dates in the form of yyyy-mm-dd.
I usually echo the whole date but now I need to echo just the yyyy. How do I do that?
I tried with echo date ("Y",$myvar) but that was not correct.
There's probably a better way, but:
$slash="-"; $split=split($slash,$date); $year= $split[0];
You can do what martin says, or format while you query
select to_char('yyyy',date_column) Formatted_Date from table_name
Hi, thanks both!
Since I needed the full date format earlier in the form I couldn't do it in the query. Martins way worked fine. (I'm getting a blank space after yyyy however. Don't know why - but I can live with that!
/c
<? $date = '2002-05-22'; $date_timestamp = strtotime ($date); $date_year = date ('Y', $date_timestamp); ?>