Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 914565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:44:21+00:00 2026-05-15T17:44:21+00:00

I have a problem extracting the year out of a mysql timestamp field. I

  • 0

I have a problem extracting the year out of a mysql timestamp field. I managed to get it work with a datetime field using this method:

SELECT id FROM TABLE WHERE YEAR(creation_date) = 2010

CREATE TABLE IF NOT EXISTS `pub_media` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `parent_id` int(11) DEFAULT NULL,
  `title` text,
  `filename` text,
  `path` text,
  `serv_path` text,
  `type` enum('images','videos','files','audio','gallery') DEFAULT NULL,
  `keywords` text,
  `label_id` int(11) DEFAULT NULL,
  `creation_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `update_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  `rank` int(11) NOT NULL DEFAULT '0',
  `deleted` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Server version : 5.1.41
Is there a simalar way to perform this action on a timestamp field? I want to keep this action in my SQL statement and not try to move it to PHP or any other scripting language, if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:44:22+00:00Added an answer on May 15, 2026 at 5:44 pm

    What problem are you encountering, and can you include the output of CREATE TABLE in your question? This works for me on MySQL 5.1.41-3ubuntu12.3:

    DROP TABLE IF EXISTS `table1`;
    
    CREATE TABLE `table1` (
        `id` int(11) NOT NULL auto_increment,
        `ts` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB;
    
    INSERT INTO table1 (id) VALUES (1);
    
    SELECT * FROM table1;
    +----+---------------------+
    | id | ts                  |
    +----+---------------------+
    |  1 | 2010-07-05 15:32:11 |
    +----+---------------------+
    
    SELECT id FROM table1 WHERE YEAR(ts) = 2010;
    +----+
    | id |
    +----+
    |  1 |
    +----+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I work with MySQL Server 5.5 and I have a problem in extracting my
I have problem with my query on C, I’m using the oci8 driver. This
I have the problem where i have a WPF RichTextBox, and i'm extracting its
I have this regular expression: ([http://some.url.com/index.php?showtopic=\]*)([0-9]+(?:\.[0-9]*)?) its for extracting links to topics from forum
I have a problem that sscanf solves (extracting things from a string). I don't
I'm using BufferedReader to read a .csv file. I have no problem reading the
Ok so I have this problem. For some reason whenever I read a file
I have problem extracting data of the Oracle custom type from the database. One
I am having a problem extracting a substring from a string using regex. For
I have problem with code. I have written a function for extracting a parameter,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.