Jump to content

[SOLVED] How do I display just the year with a datetime field?


limitphp

Recommended Posts

You can use substr() also.

 

$current_date = $row['date_time_field'];
$year = substr($current_date, 0, 10); //we assume your time stamp is 0000/00/00 00:00:00
echo $year;  // so we have 0000/00/00 for output.

Just a side note for you limit, pulling it out of MySQL in the correct format is the preferred way as it is more efficient and produces much less code. If you want to add more code, I would go with flyhoney's way.

 

Just an fyi =) (Why write code to process it when you can pull it out exactly how you need it?)

 

Just a side note for you limit, pulling it out of MySQL in the correct format is the preferred way as it is more efficient and produces much less code. If you want to add more code, I would go with flyhoney's way.

 

Just an fyi =) (Why write code to process it when you can pull it out exactly how you need it?)

 

 

How would I pull just the year out of the table?  Yes, its in 2008-11-02 08:10:25 format.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.