3D-kreativ Posted July 7, 2010 Share Posted July 7, 2010 Hi, I only get this error message in MySQL Workbench, version 5.2.25, "Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CURDATE' at line 5" CREATE TABLE Orders ( OrderId int NOT NULL, ProductName varchar(50) NOT NULL, OrderDate datetime NOT NULL DEFAULT CURDATE(), PRIMARY KEY (OrderId) ) The code is from http://www.w3schools.com/sql/func_curdate.asp I'm surprised they have an example that not works!? Preciate some help! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/206991-error-when-creating-table-with-curdate/ Share on other sites More sharing options...
bh Posted July 7, 2010 Share Posted July 7, 2010 Hi, In turn it seems ok. Try CURRENT_DATE() or CURRENT_DATE, which are synonyms of CURDATE Quote Link to comment https://forums.phpfreaks.com/topic/206991-error-when-creating-table-with-curdate/#findComment-1082365 Share on other sites More sharing options...
3D-kreativ Posted July 7, 2010 Author Share Posted July 7, 2010 Thanks, but it didn't work! Strange! Quote Link to comment https://forums.phpfreaks.com/topic/206991-error-when-creating-table-with-curdate/#findComment-1082369 Share on other sites More sharing options...
bh Posted July 7, 2010 Share Posted July 7, 2010 Then try it with NOW() function. NOW() is almost equivalent with CURDATE() except NOW() has time parts (but i think its ok for you). Quote Link to comment https://forums.phpfreaks.com/topic/206991-error-when-creating-table-with-curdate/#findComment-1082370 Share on other sites More sharing options...
PFMaBiSmAd Posted July 7, 2010 Share Posted July 7, 2010 You cannot use a function to supply a default value. From the mysql documentation - ... the default value must be a constant; it cannot be a function or an expression. The disclaimer from the bottom of the w3schools web page - We do not warrant the correctness of its content. The risk from using it lies entirely with the user. You can cause the current datetime to be entered into a column if you use a TIMESTAMP data type - The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column. See Section 10.3.1.1, “TIMESTAMP Properties”. Quote Link to comment https://forums.phpfreaks.com/topic/206991-error-when-creating-table-with-curdate/#findComment-1082489 Share on other sites More sharing options...
3D-kreativ Posted July 9, 2010 Author Share Posted July 9, 2010 Hmm, so I can't use CURTIME and CURDATE when I create the table? I thought it was possible to get the time and date every time into each column when a new row is added to the table with other information? Could it be done in some other way? To use PHP date variables into the columns each time can't be better? If possible show me some code. Preciate som help! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/206991-error-when-creating-table-with-curdate/#findComment-1083475 Share on other sites More sharing options...
fenway Posted July 9, 2010 Share Posted July 9, 2010 You can, with magical TIMESTAMPs. Quote Link to comment https://forums.phpfreaks.com/topic/206991-error-when-creating-table-with-curdate/#findComment-1083545 Share on other sites More sharing options...
3D-kreativ Posted July 9, 2010 Author Share Posted July 9, 2010 OK, like this: created TIMESTAMP DEFAULT NOW() But is it possible to create a column each for date and time and separate them? Quote Link to comment https://forums.phpfreaks.com/topic/206991-error-when-creating-table-with-curdate/#findComment-1083599 Share on other sites More sharing options...
fenway Posted July 9, 2010 Share Posted July 9, 2010 That's not the correct syntax -- check the refman. No -- why separate two intricately related pieces of information? Quote Link to comment https://forums.phpfreaks.com/topic/206991-error-when-creating-table-with-curdate/#findComment-1083739 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.