Fun at zangOOr Click Here
0 like 0 dislike
122 views
In SQL Server it's getdate(), what is the equivalant for MySQL? I'm using 5.x.
in Education & Reference by (790 points) | 122 views

1 Answer

0 like 0 dislike

IMPORTANT EDIT: It is now possible to achieve this with DATETIME fields since MySQL 5.0

Previous versions can't do that with DATETIME...

But you can do it with TIMESTAMP:

mysql> create table testtable (str varchar(32), date TIMESTAMP DEFAULT 
CURRENT_TIMESTAMP);
Query OK, 0 rows affected (0.00 sec)

mysql> desc testtable;
+-------+-------------+------+-----+-------------------+-------+
| Field | Type        | Null | Key | Default           | Extra |
+-------+-------------+------+-----+-------------------+-------+
| str   | varchar(32) | YES  |     | NULL              |       | 
| date   | timestamp   | NO   |     | CURRENT_TIMESTAMP |       | 
+-------+-------------+------+-----+-------------------+-------+
2 rows in set (0.00 sec)

mysql> insert into testtable (str) values ("demo");
Query OK, 1 row affected (0.00 sec)

mysql> select * from test;
+------+---------------------+
| str  | date                  |
+------+---------------------+
| demo | 2008-10-03 22:59:52 | 
+------+---------------------+
1 row in set (0.00 sec)

mysql>

 

by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
2 like 0 dislike
1 answer
2 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Feb 17, 2014 in Education & Reference by Simmi (640 points) | 108 views
1 like 0 dislike
1 answer

Where your donation goes
Technology: We will utilize your donation for development, server maintenance and bandwidth management, etc for our site.

Employee and Projects: We have only 15 employees. They are involved in a wide sort of project works. Your valuable donation will definitely boost their work efficiency.

How can I earn points?
Awarded a Best Answer 10 points
Answer questions 10 points
Asking Question -20 points

1,245 questions
1,400 answers
565 comments
4,809 users