how to insert datetime into database using ASP?

B

Bon

Dear all

How can I convert a datetime in Short Date format to General Date
format and then insert into SQL database?

I get a date from a field using Request("in_date"), which is in Short
Date format. Afterwards, I need to convert it into General Date and
then insert the date into database. But, the date is always inserted as
1/1/1900. Please give me some suggestions.

Cheers
Bon
 
B

Bobbo

Bon said:
How can I convert a datetime in Short Date format to General Date
format and then insert into SQL database?

You're best off avoiding tampering with date formats wherever possible
- try to just store the date early on and format it when it's being
read back out of the database. This way helps to avoid regional
descrepancies and such.

the date is always inserted as
1/1/1900. Please give me some suggestions.

This could be happening for one of several reasons:

1. You're working on some kind of history database and the original
date entered was the 1st Jan 1900. I'm guessing this is the least
likely option.
2. Your format conversion code has a bug. See my comment earlier.
3. The date isn't being passed to the table correctly and it has a
default value set, which is being picked up.
4. Something else bad is happening.
 
B

Bob Barrows [MVP]

Bon said:
Dear all

How can I convert a datetime in Short Date format to General Date
format and then insert into SQL database?

I get a date from a field using Request("in_date"), which is in Short
Date format. Afterwards, I need to convert it into General Date and
then insert the date into database. But, the date is always inserted
as 1/1/1900. Please give me some suggestions.
http://www.aspfaq.com/show.asp?id=2040
 
E

Egbert Nierop \(MVP for IIS\)

Bon said:
Dear all

How can I convert a datetime in Short Date format to General Date
format and then insert into SQL database?

I get a date from a field using Request("in_date"), which is in Short
Date format. Afterwards, I need to convert it into General Date and
then insert the date into database. But, the date is always inserted as
1/1/1900. Please give me some suggestions.

I would not convert it yourselves. A difference in the country setting of
SQL and your current thread on ASP could cause difficulties already.

Set cmd = CreateObject("ADODB.Command")
'samples, assume field2 and field1 dates

set cmd.activeconnection = myconn

cmd.commandtext = "INSERT INTO myTable(field1, field2) VALUES(?,?)"
cmd.commandtype =1
cmd.parameters.append cmd.createparameter(, 135,,,CDate(mydate))
cmd.parameters.append cmd.createparameter(, 135,,,#1-1-2025#)
cmd.execute ,, 128
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top