开发者

Set date format with existing records php mySQL. How?

开发者 https://www.devze.com 2023-04-07 17:38 出处:网络
I have a mySQL with a table.There are 30 records all with a date column. How do I change all my existing records in my table to have today\'s da开发者_运维技巧te with is format?

I have a mySQL with a table. There are 30 records all with a date column.

How do I change all my existing records in my table to have today's da开发者_运维技巧te with is format?

date_default_timezone_set('America/Los_Angeles');
$date = date("m/d/y g:i A") ; 


Here's the fix for the VARCHAR to DATETIME (this will erease the current value):

ALTER TABLE mytable modify column `mycolumn` datetime NOT NULL DEFAULT 0;
UPDATE mytable SET mycolumn = NOW() WHERE ...;

or

UPDATE mytable SET mycolumn = '2011-09-25 17:40:00' WHERE ...;

If you want to save the current value use:

ALTER TABLE mytable add column `newdate` datetime NOT NULL DEFAULT 0;
UPDATE mytable SET newdate = mycolumn;
ALTER TABLE mytable DROP COLUMN mycolumn;

If you want to select the date in the format you can:

SELECT DATE_FORMAT(mycolumn, '%m/%e/%y %h:%i %p') FROM mytable WHERE ...

Or in your PHP you can use:

date_default_timezone_set('America/Los_Angeles');

// query select ($row = mysql_fetch_assoc($query)...

$date = $date = date("m/d/y g:i A", strtotime($row['mycolumn']));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号