View Full Version : inserting a date in an access database
gibby
09-09-2002, 04:04 AM
I keep getting an sql error message when i try to enter a date into the database from asp. Im using jscript but the vb code wont be much different. heres a cpl of statements I tried:
var dt = new Date();
SQL:
var SQL = "INSERT INTO News (date) VALUES (# dt #)"
ERROR:
Syntax error in INSERT INTO statement.
SQL:
var SQL = "INSERT INTO News (date) VALUES (#09/09/2002#)"
ERROR:
Syntax error in INSERT INTO statement.
anyone got any suggestions?? ive tried loads of different things aswell but none of them seem to work
Roy Sinclair
09-09-2002, 04:25 PM
The basic problem is that date is a reserved word and you're trying to use it as a field name. You've been looking at the wrong part of the statement. Use [date] instead, the [] around the field name override it's reserved word status.
Morgoth
09-09-2002, 05:27 PM
A great neat trick for an access db and the date can be, if you go into access and open your table
Make a field called D_ate or Mydate or T_date (t = the first anitial of your project)-(using the word date will not work)
Now that you have a table and a field, we will add the date in.
This is the fun part:)
Go into design view, and go over to the field t_date or what ever you called it.
Chose Datan Type "Date/Time"
Go to formate and choose the formate you want it stored in. Do "General Date" if your not to sure on what you want.
Now go down and view "default value".
In there, put "Now()". Without the quotes, of course.
save it.
Then just open it up.
You will see that the date and time is already there. Now you no longer have to add the date in to your SQL statments. It will auto update when a new line is entered.
Hope I helped :)
whammy
09-09-2002, 11:38 PM
That sounds familiar. ;)
Morgoth
09-10-2002, 12:48 AM
Originally posted by whammy
That sounds familiar. ;)
L0L
gibby
09-11-2002, 02:17 PM
cheers, it was thick posting the question in the first place I forgot that date was a reserved word :) I got it working about 2 mins after I realised it was a reserved word but ill try what morgoth said.
Morgoth
09-11-2002, 02:29 PM
Compliments towards whammy with that one :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.