473,508 Members | 2,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to insert datetime into database using ASP?

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
3 16342

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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
13368
by: george | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, on an NT box, Active Server pages with Javascript, using ADO objects. ...
18
10248
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
9
3449
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM,...
3
3649
by: | last post by:
I have a datetime field in table. I want to insert the current time of database server to the table thr ASP.NET (C#). I have dataset to do the insert: DataSet1.TableNameRow rowNew =...
3
3427
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
4
4591
by: kd | last post by:
Hi All, I have a datetime column in a table on the SQL database. I need to insert values into the datetime column from vb.net code. Here is my code: dim nameval, str, qry as string nameval =...
6
14865
by: Marcel Hug | last post by:
Hi all ! I have a table in my database, which has 3 attributes. IDFailureControl, ControlDate and ControlVersion. In the following function I test, if the date of today allready exists. Then I...
6
3439
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
3
4689
by: iKiLL | last post by:
Hi all I am having problems getting my SqlCeDataAdapter to Update the SQL Mobile Data base. i am using C# CF2. I have tried this a number of different ways. Starting with the command builder...
4
3419
by: =?Utf-8?B?U2FpbXZw?= | last post by:
Hello to all. Please help me. I'm inserting a date into sqlserver 2005 using C#3. my problem is while insert is successfull my date and time. It's possible to insert only a date? -- To be...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.