473,513 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

insert current date/time

Hi all, I have a question about inserting records into sql server. I
am brand new to sql server, always using oracle previously. Before
today, I had always written statement such as this:

INSERT INTO TABLE (COL1) VALUES SYSDATE;

How is this accomplished in sql? I am using a datetime data type, I
hope that is correct . . .

Thank you for your help.
Ryan

p.s. I tried getdate(), getdate, sysdate, and current_timestamp. All
to no avail :(

Jul 23 '05 #1
5 165915
Hi Ryan,

I'm new to SQL Server myself, but for your question, this works for me:

INSERT INTO MyTable (colA)
VALUES (GetDate())

HTH

--
Message posted via http://www.sqlmonster.com
Jul 23 '05 #2
INSERT INTO TABLE (COL1) VALUES SELECT getdate()

--
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.developersdex.com/gurus/default.asp?p=4223
---------------------------------------

Jul 23 '05 #3
correction

INSERT INTO TABLE (COL1) SELECT getdate()
or
SELECT getdate() INTO TABLE
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.developersdex.com/g*urus/default.asp?p=4223

Jul 23 '05 #4
On 12 May 2005 16:40:38 -0700, ry*********@gmail.com wrote:
Hi all, I have a question about inserting records into sql server. I
am brand new to sql server, always using oracle previously. Before
today, I had always written statement such as this:

INSERT INTO TABLE (COL1) VALUES SYSDATE;
Hi Ryan,

Is this a straight copy-and-paste from working Oracle code? The SQL
standard calls for parentheses in the values clause.
(snip)p.s. I tried getdate(), getdate, sysdate, and current_timestamp. All
to no avail :(


Both CURRENT_TIMESTAMP (the ANSI-standard keyword) and getdate() (the
T-SQL proprietary equivalent) should work - but only if you include the
parentheses, and escape the tablename ("table" is a reserved word):

INSERT INTO "TABLE" (COL1) VALUES (CURRENT_TIMESTAMP);

If this doesn't work, then post back with the DDL (the CREATE TABLE
statement used for your table "TABLE"), the complete code, and the exact
error message you get.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #5
Hi everyone! Thanks for all of your responses . . . I believe my
problem was I was trying to insert getdate() into the datetime column
in question using the enterprise manager gui thingy. When I try the
same as an insert statement, it works fine. I was giving the
enterprise manager too much credit :)

Thanks again and have a great weekend!
Ryan

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3052
by: vishal | last post by:
i want to store the date and time when the user registered i.e. the record is entered in my table. so how can i achieve this???? should i use php or mysql to achieve this?? which is more...
2
10063
by: toedipper | last post by:
Hello, I have the following section of php code which updates a mysql record from a form. For the values of livedate and livetime I need to insert the current_date() and current_time()...
2
6712
by: mattmerc | last post by:
Hi, I would like to have a date_last_modified field for one of my SQL tables. Instead of coding my front end to keep up with this field is there a way to user a formula for this column in...
2
7642
by: lphuong | last post by:
Access 2000 I have a fldCreateDate on frmCustomer(mainform)and also a fldCreateDate on frmCustomerVisit(subform). They are one to many relationship. On the main form, frmCustomer, I have a...
1
6212
by: George LAZAR | last post by:
how can I change the system current date (time) using c#? thank you George
3
1971
by: William Cruz | last post by:
Is there a way to get the current date / time on a remote PC? William *** Sent via Developersdex http://www.developersdex.com ***
6
9530
by: trytobreak | last post by:
Hi All, I am a network administrator in a fairly large software company and I would like to write myself a small utility, which would connect (one by one) to all machines on the network and get...
3
11838
by: perhapscwk | last post by:
I using a insert query to insert some data into mysql. I use now() as the current date and time but it always have 3.X hours different from actual date. what i should use instead? thanks.
12
3153
by: AccessBeetle | last post by:
I have a qry bound form showing the search results based on the user entered criteria. There is a button called Edit on that form. The form is locked initally to stop user to edit any record...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.