Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't enter date into postgres field with datatype timestamp

Tags:

php

postgresql

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?

like image 985
Elitmiar Avatar asked Aug 21 '09 12:08

Elitmiar


1 Answers

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';
like image 196
Eric Avatar answered Sep 19 '22 15:09

Eric