Re: Insterting date in an MySQL table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "charalambos nicolaou" <npambos@xxxxxxxxxxx>

> I want to created a MYSQL table which will get the date in the form
> (YYYY-MM-DD) automatically. I have created the table below but it doesn't
> get the form of date that I want. It has the form (YYYYMMDDHHMMSS)
>
> CREATE TABLE questions1 (ID INT NOT NULL AUTO_INCREMENT,name
VARCHAR(30),day
> TIMESTAMP,question TEXT,email VARCHAR(30),answer TEXT, PRIMARY KEY(ID));
>
> Is there any other date field that gets the date form as I want?

TIMESTAMP and DATETIME columns are YYYYMMDDHHMMSS. DATE columns are YYYYMMDD
and TIME columns are HHMMSS.

Now, if you're looking for the features of a TIMESTAMP column (auto set to
current date/time upon insert/update), then you have two options. You can
make the column a TIMESTAMP(8) which will only store YYYYMMDD.  You can also
use DATE_FORMAT() when selecting your data to select the date formatted
however you want or use date() and strtotime() in PHP to format the date
from YYYYMMDDHHMMSS to whatever you want.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux