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

  • Home
  • SEARCH
  • 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 7419321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:02:55+00:00 2026-05-29T08:02:55+00:00

When I was yound and stupid had little experiance, I decided it would be

  • 0

When I was yound and stupid had little experiance, I decided it would be a good idea, to generate timestamps in PHP and store them in INT column in my MySQL innodb table. Now, when this table has millions of records and needs some date-based queries, it is time to convert this column to TIMESTAMP. How do I do this?

Currenlty, my table looks like this:

id (INT) | message (TEXT) | date_sent (INT)
---------------------------------------------
1        | hello?         | 1328287526
2        | how are you?   | 1328287456
3        | shut up        | 1328234234
4        | ok             | 1328678978
5        | are you...     | 1328345324

Here are the queries I came up with, to convert date_sent column to TIMESTAMP:

-- creating new column of TIMESTAMP type
ALTER TABLE `pm`
  ADD COLUMN `date_sent2` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP();

-- assigning value from old INT column to it, in hope that it will be recognized as timestamp
UPDATE `pm` SET `date_sent2` = `date_sent`;

-- dropping the old INT column
ALTER TABLE `pm` DROP COLUMN `date_sent`;

-- changing the name of the column
ALTER TABLE `pm` CHANGE `date_sent2` `date_sent` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP();

Everything seems correct to me, but when time comes for the UPDATEpmSETdate_sent2=date_sent;, I get a warning and timestamp value remains empty:

+---------+------+--------------------------------------------------+
| Level   | Code | Message                                          |
+---------+------+--------------------------------------------------+
| Warning | 1265 | Data truncated for column 'date_sent2' at row 1  |

What am I doing wrong and is there a way to fix this?

  • 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-29T08:02:57+00:00Added an answer on May 29, 2026 at 8:02 am

    You’re nearly there, use FROM_UNIXTIME() instead of directly copying the value.

    -- creating new column of TIMESTAMP type
    ALTER TABLE `pm`
      ADD COLUMN `date_sent2` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP();
    
    -- Use FROM_UNIXTIME() to convert from the INT timestamp to a proper datetime type
    -- assigning value from old INT column to it, in hope that it will be recognized as timestamp
    UPDATE `pm` SET `date_sent2` = FROM_UNIXTIME(`date_sent`);
    
    -- dropping the old INT column
    ALTER TABLE `pm` DROP COLUMN `date_sent`;
    
    -- changing the name of the column
    ALTER TABLE `pm` CHANGE `date_sent2` `date_sent` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to automatically create graphs of Hardness H and Young's modulus E
So I have a list of dealers names and I am searching them in
this might be stupid question, but: When I moved from ASM to C (no,
Having Watched this video by Greg Yound on DDD http://www.infoq.com/interviews/greg-young-ddd I was wondering how
I have stubbornly decided to learn Xlib programming for Linux GUIs, just for fun
As a young professional in .Net, I noticed that there are plenty of .Net
In my admittedly young career I've found myself writing code to support quirky business
I know PyCharm is young IDE but id like to know if you guys
I wathced a screen cast on DDD by Greg Young the other day which
Please let me know what is the best way to determine composition of young

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.