473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Insert Date into SQL Server

Hi, I am trying to enter data into a table,
but I got problems with my sql statement.

It's something like that:

Dim now As String = DateTime.Now.ToString
INSERT INTO table (date) VALUES(now)

I know there is also ToShortDateString but it didn't change my String in
anyway.

Atm the date in the SQL String looks like: 20.5.2004 09:00:00
and it should like like: 20-May-2004 09:00

Any idea how that is to be done???

Thx,

Stefan
Nov 20 '05 #1
10 33545
Hi

You need to convert to YYYY-MM-DD HH:MM:SS before you can
insert into ms sql server 2000.

Kind Regards
Jorge
-----Original Message-----
Hi, I am trying to enter data into a table,
but I got problems with my sql statement.

It's something like that:

Dim now As String = DateTime.Now.ToString
INSERT INTO table (date) VALUES(now)

I know there is also ToShortDateString but it didn't change my String inanyway.

Atm the date in the SQL String looks like: 20.5.2004 09:00:00and it should like like: 20-May-2004 09:00

Any idea how that is to be done???

Thx,

Stefan
.

Nov 20 '05 #2
* "Stefan Richter" <sp**@spammenot.com> scripsit:
Hi, I am trying to enter data into a table,
but I got problems with my sql statement.

It's something like that:

Dim now As String = DateTime.Now.ToString
INSERT INTO table (date) VALUES(now)

I know there is also ToShortDateString but it didn't change my String in
anyway.

Atm the date in the SQL String looks like: 20.5.2004 09:00:00
and it should like like: 20-May-2004 09:00


Use an 'InsertCommand' + parameters instead:

Using Parameters with a DataAdapter
<URL:http://msdn.microsoft.com/library/en-us/cpguide/html/cpconusingparameterswithdataadapters.asp>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Yeah, that is just what I am trying to do!

I found out that you can use this format in the brackets of the toString
method,

but it never accepts the space between the DD and HH!

DateTime.Now.ToString("YYYY-MM-DD HH:MM")
Stefan
Nov 20 '05 #4
To connect to the MS SQL Server I am using ODBC, just in case that makes any
difference!

Thx,

Stefan
Nov 20 '05 #5
Yeah, that is just what I am trying to do!

I found out that you can use this format in the brackets of the toString
method,

but it never accepts the space between the DD and HH!

DateTime.Now.ToString("YYYY-MM-DD HH:MM")
Stefan
Nov 20 '05 #6
To connect to the MS SQL Server I am using ODBC, just in case that makes any
difference!

Thx,

Stefan
Nov 20 '05 #7
either do this

DateTime.Now.ToString("YYYY-MM-DD") & " " & DateTime.Now.ToString("HH:MM")")
or
Format(Date.Now, "yyyy-mm-dd HH:MM")

you can always use CDate if you are unsure of its proper format

BTW any proper date format will work when trying to insert data into a MSSQL
2000 datetime field. This means

January 1, 2000
January 1, 2000 01:00:00
1/1/2000
1/1/2000 01:00:00
2000-01-01
2000-01-01 01:00:00

are all valid.


"Stefan Richter" <sp**@spammenot.com> wrote in message
news:c8***********@otis.netspace.net.au...
To connect to the MS SQL Server I am using ODBC, just in case that makes any difference!

Thx,

Stefan

Nov 20 '05 #8
O' the date structure is setup in the MSSQL settings of your database i.e.
in My server the date would use "/" and ":" as delimiters. if you need the
data in a certain format that is not supported then you will have to use
anther field type or format the output when the data is extracted or alter
the settings of your dB
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2h************@uni-berlin.de...
* "Stefan Richter" <sp**@spammenot.com> scripsit:
Hi, I am trying to enter data into a table,
but I got problems with my sql statement.

It's something like that:

Dim now As String = DateTime.Now.ToString
INSERT INTO table (date) VALUES(now)

I know there is also ToShortDateString but it didn't change my String in
anyway.

Atm the date in the SQL String looks like: 20.5.2004 09:00:00
and it should like like: 20-May-2004 09:00
Use an 'InsertCommand' + parameters instead:

Using Parameters with a DataAdapter

<URL:http://msdn.microsoft.com/library/en...nusingparamete
rswithdataadapters.asp>
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #9
* "Stefan Richter" <sp**@spammenot.com> scripsit:
To connect to the MS SQL Server I am using ODBC, just in case that makes any
difference!


Did you read my reply?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #10
* "Stefan Richter" <sp**@spammenot.com> scripsit:
I found out that you can use this format in the brackets of the toString
method,

but it never accepts the space between the DD and HH!

DateTime.Now.ToString("YYYY-MM-DD HH:MM")


The string doesn't work at all because "DD" is not defined, "MM" stands
for the month, and...

\\\
MsgBox(DateTime.Now.ToString("yyyy-MM-dd HH:mm"))
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #11

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

Similar topics

18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
7
by: Arek | last post by:
Hey, I am inserting values in the table: Dim sqlcomm1 As SqlCommand = New SqlCommand("INSERT INTO tblTasks (idTask, outdate) VALUES ('" & IDTask.text & "','" & txtOutdate.Text & "')", conn)...
1
by: SSG | last post by:
How to insert date to the sql server database. I am getting input from the HTML form and store it to database using ASP. how to store date field, what datatype needed and what conversion...
0
by: sourabhmca | last post by:
hi friend, I am want to insert date with time into sql server2000 using JSP.I hv 3 combo box for dd mm yyyy and 2 text box for hh and min ? and my table field type is smalldatetime.after that i ...
1
by: yzlin04 | last post by:
Does anyone know how to insert date into vb.net datagrid by using INSERT INTO command? From the code below, the error message is in cmd.ExecuteNonQuery() line. Here is the error message: An...
0
by: raoofahmedkhan | last post by:
Hi All, I am trying to develop an application in vb.net in which i need to insert date in oracle database, my application is in vb.net. i am getting some problem while inserting date. Does...
5
by: zensunni | last post by:
I like to use this method when inserting into a database: Set Insert = Server.CreateObject("ADODB.Recordset") Insert.Open "test", objConn, 1, 3, 2 Insert.AddNew Insert("FIRSTNAME") = "Joe"...
4
by: AXRabbit | last post by:
Hi, i am now doing a Car rental system web project. Well the interface is very similiar to http://www.avis.com.sg/, which i have extra modelname dropdownlist. Here is my code.Label 7 is just a...
2
by: ankitjain100 | last post by:
Hello Guys, This is my first question on this platform. I want to ask that How to insert Date in MY SQL in the MM-DD-YY format i am using JSP as my frontend. Please tell me , i will be very...
0
by: suvarn sawant | last post by:
I have written jsp code to insert date in oracle but its giving error null.my code is: String query="insert into test_KMS_DATA_ROW...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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...

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.