I\'m having problems getting the date inserted properly into my database.
$date = date(\'m/d/Y h:i:s\', time());
I use this format, and, it
Try this instead
$date = date('Y-m-d H:i:s');
<?php $date= date("Y-m-d");
$time=date("H:m");
$datetime=$date."T".$time;
mysql_query(INSERT INTO table (`dateposted`) VALUES ($datetime));
?>
<form action="form.php" method="get">
<input type="datetime-local" name="date" value="<?php echo $datetime; ?>">
<input type="submit" name="submit" value="submit">
If you're looking to store the current time just use MYSQL's functions.
mysql_query("INSERT INTO `table` (`dateposted`) VALUES (now())");
If you need to use PHP to do it, the format it Y-m-d H:i:s
so try
$date = date('Y-m-d H:i:s');
mysql_query("INSERT INTO `table` (`dateposted`) VALUES ('$date')");
The best way to make it easier and efficient is this:
CREATE TABLE table_name (
field1,
..
..
time_updated timestamp default current_timestamp
)
Now, when you insert a row into table, you can skip this field (time_updated
) as it will fill with current time as default value
use this
$date = date('m/d/Y h:i:s', time());
and then in MYSQL do
type=varchar
then date and time will be successfully inserted
Just use with your timezone :
date_default_timezone_set('Asia/Kolkata');
$date=date("Y/m/d h:i:sa");