Date & Time Input

T

Tamer Ibrahim

Hi,
I have two different text boxes. One is for reading user input date and the
other is for reading user input time.I'm using SQL 2005.
How can concatenate both of the two fields and send them as one data value
to be saved in a datetime field in the database?
 
Z

zzzxtreme

u can insert in table like this

'1/1/2001 12:00:00 AM'

month/day/year hour:minutes:seconds AM/PM

I do not know other format.
 
M

Mark Rae [MVP]

I have two different text boxes. One is for reading user input date and
the
other is for reading user input time.I'm using SQL 2005.
How can concatenate both of the two fields and send them as one data value
to be saved in a datetime field in the database?

If e.g. the first TextBox contained "17 Jul 2008" and the second contained
"08:15"

Convert.ToDateTime(TextBox1.Text + " " + TextBox2.Text);
 
M

Mark Rae [MVP]

You can insert in table like this

'1/1/2001 12:00:00 AM'

That it an ambiguous date format and should not be used...

E.g. '3/9/2001 12:00:00 AM" will be interpreted as either 3rd September or
9th March depending on the SQL Server settings and/or locale of the server
machine...
 
M

Milosz Skalecki [MCAD]

I don't think it should be sent as string and parsed by SQL server, it's
safer to convert it to DateTime and passing as SqlDbType.DateTime (4 byte
number) as you showed in your second reply.

Regards
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top