Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 14th, 2005, 08:53 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 198
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via MSN to itHighway
Default ASP, Sql Server DateTime field

Hello,

I am having problem with DateTime field in Sql Server db.

FieldName: LastActionBy
FieldType: DateTime

I want to Update Current Date and Time and using following query.

"Update LOGS SET LastActionBy = '"& NOW() &"' WHERE ID = 5"

The error I get is
"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value"

The above mentioned query was working fine. But now it is not.



I tried following queries as well, but getting same result.
"Update LOGS SET LastActionBy = "& NOW() &" WHERE ID = 5"
"Update LOGS SET LastActionBy = #"& NOW() &"# WHERE ID = 5"


Please help!!


Regards
Zeeshan Ahmed


 
Old August 14th, 2005, 06:32 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

There is nothing wrong with your first query. The error leads me to believe your date format is incorrect. write your query to the browser, what format is the date: dd/mm/yyyy, mm/dd/yyyy, yyyy/dd/mm

Im my experience you should be using either mm/dd/yyyy, yyyy/dd/mm (standard) for an insert. Here in Aussie we use dd/mm/yyyy, this is the format I get dates from users, I run the following function to insert in american date format:

  FUNCTION amDate(varDate)
    IF isNull(varDate) OR Trim(varDate) = "" OR varDate = "Null" THEN
       amDate = "Null"
    ELSE
       amDate = "'" & Month(DateValue(varDate)) & "/" & Day(DateValue(varDate)) & "/" & Year(DateValue(varDate)) & " " & TimeValue(varDate) & "'"
    END IF
  END FUNCTION

Try this (single quotes not neccessary, the function puts these in there, its a good practice to always use triling semi colons):
"Update LOGS SET LastActionBy = " & amDate(NOW()) & " WHERE ID = 5;"

NOTE: This is what query analyser is for. Trial and error, test n run, change test n run ....

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Use DateTime Field kcsathish ASP.NET 2.0 Professional 0 July 15th, 2008 01:01 AM
Sql Server DateTime field Vs ASP itHighway SQL Server ASP 2 August 16th, 2005 02:38 PM
SQL Server, field length of 20000 itHighway Classic ASP Databases 3 December 27th, 2004 01:16 AM
rownum field in sql server mateenmohd SQL Server 2000 2 June 12th, 2003 04:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.