Re: cant insert unix timestamp into mysql :( - help!
| From: | php3 at developersdesk dot com | Date: | Sat, 18 Nov 2000 06:32:20 +0000 |
| Subject: | Re: cant insert unix timestamp into mysql :( - help! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-26026@lists.php.net to get a copy of this message | ||
** Reply to note from "Chris Lee" <lee@mediawaveonline.com> Fri, 17 Nov 200=
0 20:16:31 +0800
>> $query =3D "INSERT INTO $usertable VALUES(NULL," .
>> time() .
>> ",'$title','$author',' $dept')";
>
> I dont know about your query, it wont work, im almost sure of it. your
> try'n to insert "time()" not "12345678" see what I mean.
>
> try
>
> ... echo $query; ...
>
> you'll see what I mean.
Did YOU try the query? If you look closely you will find he dropped out of
the quotes, and the time() function will be called.
On the other hand, why not just use MySQL like it is supposed to be used.
You should use DATE, TIME or DATETIME for time/date fields. DATETIME is
the best container for the equivalent of time().
Your query to insert becomes:
"INSERT INTO $usertable VALUES( NULL, NOW(), $Title, $author, $dept )";
Your query to display is:
"SELECT Author, Dept, Title, " .
"DATE_FORMAT( '%D %M %H:%m', DateField ) AS TheDate ";
The date you get back is already formatted. You can get quite fancy with
this.
For more details on date/time functions that are available, and the options
for the MySQL DATE_FORMAT function see:
http://www.mysql.com/documentation/mysql/commented/manual.php?section=3DDat=
e_and_time_functions
Also, if you want a field that automagically updates itself wnen ever the
record is updated, look at the MySQL TIMESTAMP field. Look for info on
it here:
http://www.mysql.com/documentation/mysql/commented/manual.php?section=3DDat=
e_and_time_types
Rick Widmer
Internet Marketing Specialists
www.developersdesk.com
Rick Widmer
Internet Marketing Specialists
www.developersdesk.com