I have a table called order with userID, itemID , dateOfOrder
How do I insert a row with today's date?
I've tried for example:
INSERT INTO lending
VALUES(111, 1, SELECT CURDATE())
but it doesn't work. any idea what is the correct syntax?
You didn't specify which RDBMS you are using, so here are two of the main ones: If you are using MySql look at the NOW() method. If you are using Oracle check out SYSDATE. For anything else, e.g. MS SQL, some quick googling should find you an answer.
NOW, SYSDATE, etc. because I always seem to need the time as well.NOW and CURRENT_TIMESTAMP are actually the same thing in MySQL - checks out in sqlfiddle. SYSDATE and CURRENT_TIMESTAMP turn out different in Oracle, but the timestamp can take a format mask according to the docs so it can probably work out in the end. Learned some new stuff, thanks =)
getdate()? What database?SELECTis superfluous in this case. SQL statements aren't structured that way, you just call the function to get the value you need.