Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateFormat in MySQL

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
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?
 
Hi

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.

spijker

 
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
 
MySQL supports 4 date-related field types:

DATE
TIME
DATETIME
TIMESTAMP

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top