Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

DateFormat in MySQL

DateFormat in MySQL

DateFormat in MySQL

Hello again,

I am transferring my existing Access Database into MySQL. Where in access I could specify a default value of 'now()' or 'date()' in the date fields, I am unable to do so in MySQL despite extensive research.

Anybody got any ideas?

RE: DateFormat in MySQL


It depends on what context you are using yout MySQL Database in.

If you are using it to support a web based appplication the best way would be to use one of the embedded languages like PHP or the like to create the value you want and then simply feed this variable into your MySQL database.


RE: DateFormat in MySQL

You can setup a timestamp field in Mysql and set to NULL.
A timestamp is generated when field is inserted.
See "TIMESTAMP columns other than the first may also be set to the current date and time. Just set the column to NULL or to NOW(). " at http://www.mysql.com/doc/D/A/DATETIME.html

RE: DateFormat in MySQL

MySQL supports 4 date-related field types:


So for your basic needs, probably DATE is the format you want. The misunderstanding is between default value, and *routinely inserted* value when doing your queries.

Setting a default value of 'NOW()' is not what you want to do. Instead just have a DATE field, and run your INSERT statements like:

INSERT INTO table_name (id, date, etc, etc1, etc2) VALUES ('', NOW(), 'whatever', 'whatever1', 'whatever2')

Notice the NOW() has no quotes around it.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close