SunQuest
           MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old March 5th, 2004, 04:20 AM
weebeng weebeng is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 76 weebeng User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 22 sec
Reputation Power: 5
inserting datetime

hi, i'm using sql server db and i try to insert datetime into db.Can some body check for me what is the syntax error?Thanks
Code:
insert into cp_trxSeasonParker(cp_trxdatetimeout) values ('format("05/03/2003 11:15:45", "dd/mm/yyyy hh:mm:ss")')

Reply With Quote
  #2  
Old March 5th, 2004, 08:29 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,344 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 5 Days 8 h 27 m 14 sec
Reputation Power: 891
the FORMAT function is not valid for sql server

you can use the dd/mm/yy format, but you may need to set sql server's dateformat option first:
Code:
set dateformat dmy

insert into cp_trxSeasonParker(cp_trxdatetimeout) 
 values ('05/03/2003 11:15:45')
__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old March 8th, 2004, 09:09 PM
mat41 mat41 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Sydney Australia
Posts: 17 mat41 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m
Reputation Power: 0
Send a message via AIM to mat41 Send a message via Yahoo to mat41
SQL server requires you to insert dates in US date format. What ever your date is run it thru a function that does this conversion. The below function converts a dd/mm/yyy (non american format) mm/dd/yyyy (american format) into a mm/dd/yyyy (american format)

FUNCTION amDate(varDate)
amDate = "'" & Month(DateValue(varDate)) & "/" & Day(DateValue(varDate)) & "/" & Year(DateValue(varDate)) & " " & TimeValue(varDate) & "'"
END FUNCTION

when you do you insert call the function
sql = "INSERT INTO tableName (yourDateFieldname, fieldname1 , fieldname2) VALUES (amdate(yourDateValue), someValue1, someValue2);

Ensure your data type for your date field in design view is set to date. You should always set fields that hold dates to date format so you may 'search on date ranges'

If you have trouble inserting. Response.write your date before the function / run the function and write the value again. if this looks ok check your data type for the field, lastly look at your single and double quotes inside your ststements (the function places single quotes around the returned value!!!)

Reply With Quote
  #4  
Old March 8th, 2004, 09:43 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,344 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 5 Days 8 h 27 m 14 sec
Reputation Power: 891
mat41, i've been using ISO standard yyyy-mm-dd dates in sql server for years, nobody ever told me i had to use US format


Reply With Quote
  #5  
Old March 8th, 2004, 10:10 PM
mat41 mat41 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Sydney Australia
Posts: 17 mat41 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m
Reputation Power: 0
Send a message via AIM to mat41 Send a message via Yahoo to mat41
the date example given was in a format that was not identifyable to me 05/03/2003 (or something like that - no day or month number over 12). Have you ever inserted a dd/mm/yyyy format in to sql server with success?

If so which version, if not give it a go? I will re try it to satisfy my curiosity however I think you will find it errors out

What format do you use in Canada? I guess I asumed it was US.

Reply With Quote
  #6  
Old March 8th, 2004, 10:26 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,344 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 5 Days 8 h 27 m 14 sec
Reputation Power: 891
i have inserted mm/dd/yyyy, dd/mm/yyyy, yyyy-mm-dd, and even yyyy-dd-mm

for two of these you have to set dateformat dmy

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > inserting datetime


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