What property should I give a table column to record the date today.
I added timestamp, and it displays me: 2010-11-25 02:57:30
I want just the date.
Current date in mysql
Moderator: General Moderators
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Current date in mysql
What about DATE
Last edited by social_experiment on Thu Nov 25, 2010 4:52 am, edited 1 time in total.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Current date in mysql
Like:
ALTER TABLE tableName ADD today_date CURDATE() ?
This won't work.
ALTER TABLE tableName ADD today_date CURDATE() ?
This won't work.
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Current date in mysql
I solved it but not in the database level.
I did it like this.
ALTER TABLE tableName ADD today_date DATE;
Then in php:
$query1 = mysql_query("INSERT INTO tableName(today_date) VALUES(NOW())");
But I want it in the database level.
I did it like this.
ALTER TABLE tableName ADD today_date DATE;
Then in php:
$query1 = mysql_query("INSERT INTO tableName(today_date) VALUES(NOW())");
But I want it in the database level.
-
internet-solution
- Forum Contributor
- Posts: 220
- Joined: Thu May 27, 2010 6:27 am
- Location: UK
Re: Current date in mysql
[syntax]INSERT INTO tableName (today_date) VALUES (CURDATE())[/syntax]
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Current date in mysql
Thanks, but I wanted something that if I do not insert anything in the db, the default will be the current date.
-
internet-solution
- Forum Contributor
- Posts: 220
- Joined: Thu May 27, 2010 6:27 am
- Location: UK
Re: Current date in mysql
w3school says it can be done - see here - http://www.w3schools.com/sql/func_curdate.asp
But when I try their code on my server (MySQL 5.0.45), it shows an error. It only accepts current_timestamp as default value and this only works if field type is timestamp. (Edit - confirmation here - http://dev.mysql.com/doc/refman/5.0/en/ ... aults.html)
Is there a particular reason you want to add only the date?
But when I try their code on my server (MySQL 5.0.45), it shows an error. It only accepts current_timestamp as default value and this only works if field type is timestamp. (Edit - confirmation here - http://dev.mysql.com/doc/refman/5.0/en/ ... aults.html)
Is there a particular reason you want to add only the date?
Last edited by internet-solution on Thu Nov 25, 2010 8:18 am, edited 1 time in total.
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Current date in mysql
hehehe the same happens to me, I get an error
.
I want only the date, because I don't need the time.
But anyways I got it working.
Thanks.
I want only the date, because I don't need the time.
But anyways I got it working.
Thanks.