View Full Version : Display Date from MySQL in PHP form
01-11-2012, 09:08 PM
Im guessing this is going to be easy for any one to answer bc im such a ****ing noob but here goes. I have mysql fields set to DATETIME and i just want to pull out that data and have it display in my form. And i would also like to know how to insert a date into a mysql DATETIME field if you guys would be so kind as to assist. I really really would appreciate any help. Thanks guys
for whatever type of form field you have, in the value field put <?php echo $dateTime; ?> where $dateTime is equal to whatever value u've pulled from the database.
Now I'm not positive on this, but from my previous experience on using the datetime format in the mysql db, it updates every time the row is updated. I'm not sure exactly because I never looked it up and I'm sure someone is going to come around and correct me on it but from what happened to me, every time I updated the row, the time updated of when it was updated.
01-12-2012, 09:03 PM
You can get it such as:
$query = "select mydate from `dates` where id='1'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
## Use $row['mydate'] and print the date wherever you want it, as a string
To insert one, you can use the following (this depends on your localization though):
$query = "insert into `dates` (mydate) values (" . date("Y-m-d H:i:s") . ")";
mysql_query($query) or die (mysql_error());
For more information about date(), check this page:
01-12-2012, 09:55 PM
THANK YOU SO MUCH! Ive done tons of reading and you made the most sense to me. Thanks a million man.
TO everyone else who tried to help, thank you for your time. You guys are awesome
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.