MySQL datetime into PHP -
i have found proper solution "problem" after reading mysql pages, don't understand logic behind it.
i store registration information in system in "datetime" formatted field in 1 of tables (yyyy-mm-dd hh:mm:ss)
.
when want display data on 1 of php pages, posting exact field data shows format mentioned above.
i think using date("y-m-d",$row["date"])
$row["date"]
corresponds particular row value return desired format.
instead have use:date("y-m-d", strtotime($row["date"]))
.
why this? $row["date"]
field not string in first place. should able simple rearrange data stored in datetime field? wasn't purpose of rebuilding entire tableset accomodate datetime?
mysql has built in function called date_format can use display date how want to.
select date_format(date_field, '%y-%m-%d') date_field table_name
the manual has list of formats , variables needed display way. using method there no need have php convert etc. plus less code on php side mysql can handle easily.
edit
sorry, read looking explanation.
php's date
function takes in unix timestamp, mysql not using. mysql uses real date format ie: yyyy-mm-dd hh:mm:ss
, know, compliant years later. unix timestamp has limited range 1969 2037 valid for, makes useful "timestamping" of items such chat box message or items not expected around post dates, mysql datetime
should not die out until year changes 5 digits or world ends.
read wiki on unix timestamp more information on it.
Comments
Post a Comment