Re: time stamp screwing up

From: Date: Mon, 06 Jan 2003 23:21:16 +0000
Subject: Re: time stamp screwing up
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-130511@lists.php.net to get a copy of this message
A MySQL timestamp is different to a MySQL timestamp. $time = time(); will produce a unix timestamp what you want is $time = date('Y-m-d'); to give a value in the format YYYY-MM-DD I think you can also use NOW(): $query = "INSERT INTO contacts (id, name, pass, email, dateAdded) VALUES (NULL, '$name', '$pass', '$email', NOW())"; ... but I've never tried -- loook up NOW() in the MySQL manual. IF you wanted the unix stamp instead (seconds since unix epoch), you should change the column type of dateAdded to an unsigned integer of 32 bits (from what I can tell from the manual). I personally prefer unix stamps (seconds) over formatted dates (YYYY-MM-DD) because it's easy to compare them and find out the difference (subtract one from the other), add a day (add 24*60*60) etc etc, BUT it's harder (impossible) for a human to read the raw data in the DB. Good luck, Justin French on 07/01/03 3:19 AM, - [ Paul Ferrie ] - (info@innovativedesigns.org.uk) wrote: > hey guys could someone help me > I have created a user login register system in flash with PHP and Mysql. > Everthing Now works fine aprt from the time stamp of when the user > registered. > > Code ----------------------------------- > // Get current date & time > $time = time(); > // Connects to the Database. > $Connect = mysql_connect($dbServer, $dbUser, $dbPass); > mysql_select_db("$dbName"); > // Preforms the SQL query to see if user name already exsists > $query = "SELECT name FROM contacts WHERE name='$name'"; > $rs_contacts = mysql_query($query) or die(mysql_error()); > $row = mysql_fetch_assoc($rs_contacts); > if ($row[name] == $name) { > print "loginT=UserName in Use&checklog=2"; > }else{ > $query = "INSERT INTO contacts (id, name, pass, email, dateAdded) VALUES > (NULL, '$name', '$pass', '$email', '$time')"; > } > > > It inserts 0000-00-00 > instead of the current date > > ideas > > P.S > I am a newbie try keeping reponse's simple please > >

« previous php.general (#130511) next »