Jump to content

Insert Current Date


joecool308

Recommended Posts

What's a simple SQL query to add a the CURRENT DATE automatically. I want it to be displayed as ex. Jul 10, not something like 2009-10-15.maybe something like - ATLER TABLE info ADD date CURDATE; ???How do I do? I'm sure this is a simple for most of you! ty in advance

Link to comment
Share on other sites

You can add a timestamp field and give it a default value to the current timestamp, which will set it to the time the row was inserted:http://stackoverflow.com/questions/168736/...datetime-columnYou can use ON UPDATE to make it set the value to the current timestamp whenever the row is updated:http://www.databasejournal.com/features/my...-in-MySQL-5.htm

Link to comment
Share on other sites

JUSTSOMEGUY Thank youOne more though:I just added it in my php code as: $date=date("M / d");And then that goes into my table as the current date submitted by user. I will need to retrieve that same date later (not an updated date), so the above code seems to work fine. Do you see any problems with using that though?

Link to comment
Share on other sites

Worth adding the year to that probably, even if you don't use it - otherwise you won't be able to say with any certainty when the update/insert occurred.

Link to comment
Share on other sites

Yeah, it's best to use a full date, maybe even time. You can always format and display it however you want, only the month and day if you want, but it might be worth it to at least store the full date/time. If you want, the way I usually do it is to set my date column to be an int, and then I just store the Unix timestamp there, e.g.:$date = time();When you get the timestamp back out and you want to display it on the page, then you can run it through your date function to format it however you want. That will probably give you more flexibility in the future.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...