Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to insert into a field (type Datetime) from ASP to SQL Server?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-07-01 : 07:45:24
KhacTung writes "Help me, please!

I want to insert into a field (type is Datetime) from ASP to SQL Server, when input 19/6/2003 on page ASP and submit, but In table on Database SQL server only display 01/01/1900.How to submit 19/6/2003 then display 19/6/2003!

Thank you very much!"

Nazim
A custom title

1408 Posts

Posted - 2003-07-01 : 08:33:36
Are you sure , your data is reaching Sql server.

Try inserting a record thru Query analyzer , and check the result.

you can also open Sql profiler and check what data is being inserted from your ASP. i think , the problem lies in what data your submitting to insert. a word of caution. whenever you are inserting datetime in sql server. try to format it in 'dd-mmm-yyyy' and insert. coz sql server default date format is MDY, until you change it explicity.

-------------------------
What lies behind you and what lies ahead of you are small matters compared to what lies within you.-Ralph Waldo Emerson
Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2003-07-01 : 08:34:05
insert into MyTable select convert(datetime,'31/1/2003',103)

select convert(char(10), MyDateTimeField, 103) as MyDateFormat from MyTable

In other words, you pass to the SQL server just a string.
Then before inserting this string into datetime field you
convert it into datetime type value with code=103 (dd/mm/yyyy).

When you retrieve datetime value from server you convert it into
string of your preferred format and pass this string to your ASP page.

Go to Top of Page
   

- Advertisement -