Jump to content

Timestamp question?


frank_solo

Recommended Posts

I have a column that is named date_created and has a value of DATETIME. How on this script can I  insert only the time it was created. Is it NOW()) and if so how do I write it in the script?

// if residential
if($_POST['type'] == ""){
	mysql_select_db("", $con);
	$sql = "INSERT INTO apartments (username, title, county, town, type, description, phone, rooms, bath, square, rent, fees, service, imageurl1, imageurl2, imageurl3, imageurl4) VALUES ('".$myusername."', '".mysql_real_escape_string($_POST['title'])."', '".mysql_real_escape_string($_POST['county'])."', '".mysql_real_escape_string($_POST['town'])."', '".mysql_real_escape_string($_POST['type'])."', '".mysql_real_escape_string($_POST['description'])."', '".mysql_real_escape_string($_POST['phone'])."', '".$_POST[('rooms')]."', '".mysql_real_escape_string($_POST['bath'])."', '".mysql_real_escape_string($_POST['square'])."', '".mysql_real_escape_string($_POST['rent'])."', '".mysql_real_escape_string($_POST['fees'])."', '".mysql_real_escape_string($_POST['service'])."', '".mysql_real_escape_string($images[1])."', '".mysql_real_escape_string($images[2])."', '".mysql_real_escape_string($images[3])."', '".mysql_real_escape_string($images[4])."')";

$result = mysql_query($sql) or die(mysql_error());

Link to comment
Share on other sites

This article should help you understand your options.  http://www.gizmola.com/blog/archives/93-Too-much-information-about-the-MySQL-TIMESTAMP.html

 

If you alter your definition from datetime to timestamp you will save space (4 bytes per row) as well as unlocking automatic timestamping of the row.  The only issue is that if you will later update these rows, by default an update will also change the timestamp column which may not be what you want.

 

If you leave it as a datetime, then yes you can simply specify the constant 'NOW()' in the VALUES section.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.