PDA

Bekijk Volledige Versie : [mysql] datum-tijd syntax in insert-query



henq
28/04/03, 00:05
Hi,

Ik wil een datum-tijd instellen van een DATETIME kolom op bijv. 1 uur vanaf
nu. Ik wil (voor de sport) niet in perl/php programmeren, maar het puur in
sql doen.

Ik probeer zoiets als ...

INSERT INTO mijn_tabel (wek_tijd)
VALUES (DATE_ADD(NOW(), INTERVAL 3600 SECONDS))

Maar ik krijg een syntax error. Snapt iemand meer dan ik van die datum/tijd
functies van mysql? Kan je die allen met SELECT's gebruiken? (alle
voorbeelden die ik zie zijn met SELECT's).

~henq

Daniel Tryba
28/04/03, 19:50
"henq" <henq _ replace 0 by o <hvtijen@h0tmail.c0m>> wrote:
> Ik probeer zoiets als ...
>
> INSERT INTO mijn_tabel (wek_tijd)
> VALUES (DATE_ADD(NOW(), INTERVAL 3600 SECONDS))
>
> Maar ik krijg een syntax error.

Lees op
http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#Date_and_time_functions

<q>
ADDDATE(date,INTERVAL expr type)

These functions perform date arithmetic. ADDDATE() and SUBDATE() are
synonyms for DATE_ADD() and DATE_SUB(). In MySQL Version 3.23, you can
use + and - instead of DATE_ADD() and DATE_SUB() if the expression on
the right side is a date or datetime column. (See example below.) date
is a DATETIME or DATE value specifying the starting date. expr is an
expression specifying the interval value to be added or subtracted from
the starting date. expr is a string; it may start with a `-' for
negative intervals. type is a keyword indicating how the expression
should be interpreted. The following table shows how the type and expr
arguments are related:

type value Expected expr format
SECOND SECONDS
</q>

Het lijkt erop dat de seconds uit je expressie geen geldig type is.

--

Daniel Tryba