views:

27

answers:

1

Hey there, I'm using drupal and a pgsql database, but after long searches I still can't figure out how to put a CURRENT_TIMESTAMP or now() into the database when inserting a row into a table. Putting now() on the default value of a column won't work, because drupal won't accept it on the database schema, so that's out of question.

The current column type is "timestamp without timezone" or "time without timezone", which drupal's schema accepts. Now the problem is inserting a date there.

I have tried:

$now = format_date(time(), 'custom', 'Y-m-d H:i:s');

and inserting it with the string placeholder '%s', but pgsql gave me an error.

I also tried to change the type to integer and insert using time() php function, and it didn't work (if it did i'd use it on other tables), so maybe i'll stick with the timestamp type as it is makes more sense.

Thanks in advance.

A: 

Below you find my suggestions from the comments to the question.

  • You can use 'now' as a string enclosed in single quotes, but current_timestamp should not be in quotes.
  • If you have a time-stamp you must enclose it in single quotes: '2010-10-10 14:13:22'
  • You get the error "invalid syntax" because the string is empty. Check that you really have something in the variables and that it's not an empty string.
  • Your timestamp that you try to insert is missing the date.
some
It was missing the date, as it was wrongly type set as "time without timezone", and it should be "timestamp without timezone". The variables were empty, because i forgot to fetch the row. 'now' worked in both db_query("INSERT...'now' ") and drupal_write_record (good thing on this function is that you can forget the placeholders). Thanks for your help.
polar
No problem, that's what this site is all about! Now it's time to sleep for a while for me. Good night!
some