Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP 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 July 28th, 2003, 03:01 PM
Authorized User
 
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default (one last problem)... can't insert dates in SQL

Hello

Suppose many of you have faced this problem before. I try to insert a date form my ASP page in SQL Server 2000 (in a smalldatetime datatype), but this seems impossible.

After receiveing many error messages i found that i had to use the Convert function in my query. Well, I am using:

update games set game_date=CONVERT(smalldatetime, 31/07/2003)

The query works fine, but it inserts the value 01/01/1900 in the database. I also tried others formats of the date (07/31/2003 etc.) but nothing works.

It would be gretaly appreciated if could have a code snippet with an insert statement for SQL Server from ASP contaning dates.

Thanks in advance.

Nick
 
Old July 28th, 2003, 03:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can't give you ASP code, but the SQL to update a datetime datatype is:
Code:
UPDATE games SET game_date='2003-07-31';
There are several ways to deal with different date formats due to locale, but the simplest is to always use the ISO standard date format, i.e. yyyy-mm-dd. That way there is no ambiguity. Express the date as a string and all will be fine.

(BTW, the CONVERT function as you wrote it and the variations you tried will always insert a 0 as the date. A date of 0 is Jan 1, 1900. It will always insert a 0 becuase the 31/7/2003 is an expression interpreted as the integer 31 divided by the integer 7 divided by the integer 2003 truncated to an integer. The other variations also end up dividing by 2003 the result of which is always less than 1 which truncates to a 0.)


Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
insert & update statment problem (sql express) abdrabaa C# 2 July 15th, 2007 05:54 AM
help with SQL dates Byock SQL Server 2000 1 March 23rd, 2006 12:58 PM
ASP insert into sql date problem markd Classic ASP Databases 1 February 18th, 2006 10:43 AM
SQL dates - Problem malecumbria Classic ASP Databases 4 February 16th, 2005 01:18 PM
SQL Problem in access with dates tucker SQL Language 4 December 19th, 2003 12:16 PM





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