List:MySQL ODBC« Previous MessageNext Message »
From:Scott Nichols Date:July 3 2003 7:31pm
Subject:RE: Inserting Date Field
View as plain text  
FWIW, I use the following code to add a date parameter in .Net

Dim strDate as string = (get from text box)

Dim myCommand As New OdbcCommand()
myCommand.Connection = myConnection
myCommand.CommandText = "UPDATE tmp SET d=?"
myCommand.Parameters.Add("DateVar", OdbcType.Date)
myCommand.Parameters("DateVar").Value = CType(strDate,
Date).ToString("yyyy/MM/dd")
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()

Depending on your client side error handling you would want to wrap some
portion of the above statements in a try...catch block.

-Scott


-----Original Message-----
From: Kyle Holder [mailto:kyle@stripped] 
Sent: Thursday, July 03, 2003 10:42 AM
To: Ed Kraft; 'myodbc'
Subject: RE: Inserting Date Field

I keep it an actual date field.  Timestamp does not work this way (by
the
way).

K-

-----Original Message-----
From: Ed Kraft [mailto:ekraft@stripped]
Sent: Thursday, July 03, 2003 12:10 PM
To: 'Kyle Holder'; 'myodbc'
Subject: RE: Inserting Date Field


That makes sense.  So do you change the date field to type text or char
then?  Or do you keep it as an actual date field?

-----Original Message-----
From: Kyle Holder [mailto:kyle@stripped]
Sent: Thursday, July 03, 2003 7:09 AM
To: Ed Kraft; 'myodbc'
Subject: RE: Inserting Date Field


My experience is that anytime you want to do something with date
calculations, it usually doesn't work too well.  It's much easier for me
to do the date conversions on the ASP side, and then to tell MySQL
exactly what I want it to store rather than try and rely on MySQL for
those conversions. When I've attempted date conversions in the past, I
usually get empty fields (which I don't really understand, but such is
life, I guess)...

Good Luck.
K-

-----Original Message-----
From: Ed Kraft [mailto:ekraft@stripped]
Sent: Thursday, July 03, 2003 12:02 PM
To: 'Kyle Holder'; 'myodbc'
Subject: RE: Inserting Date Field


Thanks for the feedback Kyle.  I'll give it a shot.

Isn't there a way I can just insert the date into the query just using
the CURDATE value?  And not have to make a function to convert the
format?

Thanks.


-----Original Message-----
From: Kyle Holder [mailto:kyle@stripped]
Sent: Thursday, July 03, 2003 7:02 AM
To: Ed Kraft; 'myodbc'
Subject: RE: Inserting Date Field


Hope this helps...

MySQL handles dates in a yyyy-mm-dd format, so...

<%
mydate = date()

thisday = day(mydate)
if thisday < 10 then
	'dates less than 10 are formatted using one digit, but MySQL
requires 2, so we add a 0 to the beginning...
	thisday = "0" & thisday
end if

thismonth = month(mydate)
if thismonth < 10 then
	'Same thing with the month
	thismonth = "0" & thismonth
end if

thisyear = year(mydate)

mydate = "'" & thisyear & "-" & thismonth & "-" & thisday & "'"

sql = "insert into table (thisdate) values (" & mydate & ")"

conn.execute sql
%>

Kyle Holder



-----Original Message-----
From: Ed Kraft [mailto:ekraft@stripped]
Sent: Thursday, July 03, 2003 11:52 AM
To: 'myodbc'
Subject: Inserting Date Field


Hey All,

How do I insert a date field into my mySQL db?  I had it working with
Access (using the date()) function.  Now after looking here:

http://www.mysql.com/doc/en/Date_and_time_functions.html

I see that it has to be done differently.  I've tried using the CURDATE
function, but that doesn't do anything within my ASP pages.

Thanks,

Ed


--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe: http://lists.mysql.com/myodbc?unsub=1


--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe:
http://lists.mysql.com/myodbc?unsub=1


--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe:
http://lists.mysql.com/myodbc?unsub=1


-- 
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe:
http://lists.mysql.com/myodbc?unsub=1

Thread
rs.delete won't flyjoe speigle2 Jul
RE: rs.delete won't flyMike Hillyer2 Jul
  • RE: rs.delete won't flyjoe speigle2 Jul
    • RE: rs.delete won't flyEd Carp2 Jul
  • RE: rs.delete won't flyjoe speigle2 Jul
  • RE: rs.delete won't flyEd Carp2 Jul
RE: rs.delete won't flyMike Hillyer2 Jul
  • Inserting Date FieldEd Kraft3 Jul
    • RE: Inserting Date FieldKyle Holder3 Jul
      • RE: Inserting Date FieldEd Kraft3 Jul
        • RE: Inserting Date FieldKyle Holder3 Jul
          • RE: Inserting Date FieldEd Kraft3 Jul
            • RE: Inserting Date FieldKyle Holder3 Jul
              • RE: Inserting Date FieldScott Nichols3 Jul
RE: rs.delete won't flyMike Hillyer2 Jul
Re: Inserting Date FieldMichael Viron4 Jul
Re: Inserting Date FieldDaniel J. Summers5 Jul
RE: Inserting Date Fieldjbonnett7 Jul