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 60389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:09:15+00:00 2026-05-10T18:09:15+00:00

How do you set a default value for a MySQL Datetime column? In SQL

  • 0

How do you set a default value for a MySQL Datetime column?

In SQL Server it’s getdate(). What is the equivalant for MySQL? I’m using MySQL 5.x if that is a factor.

  • 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. 2026-05-10T18:09:16+00:00Added an answer on May 10, 2026 at 6:09 pm

    IMPORTANT EDIT: It is now possible to achieve this with DATETIME fields since MySQL 5.6.5, take a look at the other post below…

    Previous versions can’t do that with DATETIME…

    But you can do it with TIMESTAMP:

    mysql> create table test (str varchar(32), ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP); Query OK, 0 rows affected (0.00 sec)  mysql> desc test; +-------+-------------+------+-----+-------------------+-------+ | Field | Type        | Null | Key | Default           | Extra | +-------+-------------+------+-----+-------------------+-------+ | str   | varchar(32) | YES  |     | NULL              |       |  | ts    | timestamp   | NO   |     | CURRENT_TIMESTAMP |       |  +-------+-------------+------+-----+-------------------+-------+ 2 rows in set (0.00 sec)  mysql> insert into test (str) values ("demo"); Query OK, 1 row affected (0.00 sec)  mysql> select * from test; +------+---------------------+ | str  | ts                  | +------+---------------------+ | demo | 2008-10-03 22:59:52 |  +------+---------------------+ 1 row in set (0.00 sec)  mysql> 

    CAVEAT: IF you define a column with CURRENT_TIMESTAMP ON as default, you will need to ALWAYS specify a value for this column or the value will automatically reset itself to "now()" on update. This means that if you do not want the value to change, your UPDATE statement must contain "[your column name] = [your column name]" (or some other value) or the value will become "now()". Weird, but true. I am using 5.5.56-MariaDB

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer It's hard to know what the right answer is without… May 11, 2026 at 2:47 pm
  • added an answer The DELIMITER command is a MySQL shell client builtin, and… May 11, 2026 at 2:47 pm
  • added an answer If you are familiar with SAX, may you like SAXDotNet.… May 11, 2026 at 2:47 pm

Related Questions

How do you access the items collection of a combo box in a specific
Yes, another NULL vs empty string question. I agree with the idea that NULL
How do you implement a last-modified column in SQL? I know for a date-created
For a C# UserControl on Windows Mobile (though please answer if you know it

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.