Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

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 ASP Free Forums Sponsor:
  #1  
Old June 27th, 2004, 11:35 AM
danny__t danny__t is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 15 danny__t User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Date problems (again!)

I am trying to use asp to add/edit dates in a sql server db.

I can add a date fine using: -

INSERT INTO news(news_title, news_date, news_intro, news_text)
VALUES('The title of the news',
'25/06/2004',
'This is the introduction to the news article',
'this is the text for the news')

however when i try to update using: -

update news set news_date='23/05/2004' WHERE news_id = 11

I get the following error: -

Server: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.

the date column is of the datatype datetime
I also have the same problem if i use the same sql directly in query analyzer

Any help HUGELY appreciated, cheers

Dan

Reply With Quote
  #2  
Old June 27th, 2004, 11:46 AM
danny__t danny__t is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 15 danny__t User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
OK so it works if I use
update news set news_date='20040523' WHERE news_id = 11

so how is best to convert my date variable 'newsDate' from dd/mm/yyyy to yyyymmdd in ASP?

I have looked at the datetimeformat function but that is limited to 4 set formats none of which are what i need.

Thnaks

Reply With Quote
  #3  
Old June 27th, 2004, 11:12 PM
Tonny-Soeroso Tonny-Soeroso is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 36 Tonny-Soeroso User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 56 m 27 sec
Reputation Power: 0
Smile

Hello danny,this is my solution for u, but sorry i don't know to much in asp, this is the vb version

Private Sub Update_news()
dim rs_update as adoDB.recordset
set rs_update = new adoDB.recordset
rs_update.open "UPDATE NEWS SET NEWS_DATE = '" & FORMAT(newsDate, "YYYY - MM - DD") & "' WHERE news_id = 11", con, adOpenKeyset
set rs_update = nothing

end sub


Best Regards

Tonny

Reply With Quote
  #4  
Old June 28th, 2004, 02:11 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
You may also just want to use the FormatDateTime function like so:

update news set news_date='" & FormatDateTime("23/05/2004",2) & "' WHERE news_id = 11

This way it will guarantee that it is an acceptable time format.

I'm not meaning to say that your way is wrong Tonny, but I have found when using ASP, SQL seems to have a problem when just using FORMAT with date data types.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Date problems (again!)


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