Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.