MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 28th, 2004, 10:37 AM
jorge13 jorge13 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: New Jersey, USA
Posts: 6 jorge13 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Can't insert a date into mySQL datetime field

Hey.

I'm trying to do a simple insert into a mySQL datetime field. Actually, I've tried all the other date types and none of them work for me. Here's a test snippet ...

<code>
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=xxxx;uid=xxxx;password=xxxx"
set objRS=Server.CreateObject("ADODB.recordset")
objRS.CursorLocation=3
objRS.CursorType=3

sql = "INSERT INTO testTbl " &_
"SET date_time = '" & formatDateTime(now(),0) &"'"
objRs.Open sql,objConn
</code>

This doesn't work. I get nothing but zeros no matter what date type I use. But if I hard-code a date (e.g. 2004-01-27 12:00:00 AM), it works. Please help.

-Jorge

Reply With Quote
  #2  
Old January 28th, 2004, 12:39 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
NOW() is a mysql function that you're wrapping in non-mysql code. You should just be able to insert NOW() without wrapping it in the formatDateTime() function.

Reply With Quote
  #3  
Old January 28th, 2004, 03:46 PM
jorge13 jorge13 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: New Jersey, USA
Posts: 6 jorge13 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
dhouston,
Thanks for the quick reply. I had already tried that but I tried it agian anyway. Still doesn't work. Again I hard-coded the date and it worked fine. It's a mystery.

-J

Reply With Quote
  #4  
Old January 28th, 2004, 10:54 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
try this (based on your first code)
sql = "INSERT INTO testTbl SET date_time = NOW()'"

Reply With Quote
  #5  
Old January 28th, 2004, 11:36 PM
jorge13 jorge13 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: New Jersey, USA
Posts: 6 jorge13 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
what?

OK. what in tarnation 's goin on?

Yes! that worked! I thought the NOW() had to be outside of the string. thank you X 3 man!

Reply With Quote
  #6  
Old January 29th, 2004, 07:07 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
No, as NOW() is a mysql function, it has to be inside the string passed to mysql, where it is interpreted and converted to the current date.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Can't insert a date into mySQL datetime field


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway