I'm trying to insert a date ("This is a string") into a postgres database field. I'm getting the following error
ERROR: invalid input syntax for type timestamp: ""
Here is my code
$date = '2002-03-11';
$query = 'INSERT INTO dates(date) VALUES('.$pdo->quote($date).')';
$pdo->query($date);
I have absolutely no idea on how to do this?
You're trying to insert into a timestamp. You need to concatenate the time with the date. From the Postgres documentation:
Valid input for the time stamp types consists of a concatenation of a date and a time, followed by an optional time zone, followed by an optional AD or BC. (Alternatively, AD/BC can appear before the time zone, but this is not the preferred ordering.) Thus
1999-01-08 04:05:06
and
1999-01-08 04:05:06 -8:00
are valid values, which follow the ISO 8601 standard.
Do:
$date = '2002-03-11 12:01AM';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With