By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,752 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

how to insert datetime into database using ASP?

P: n/a
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

Jul 28 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

Bon wrote:
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.

Jul 28 '06 #2

P: n/a
Bon wrote:
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
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 28 '06 #3

P: n/a

"Bon" <bo***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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
Jul 28 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.