how can i convert time to sql server 2008 getdate() format ??

i have to insert time into sql server 2008 table , but it has format and i have to insert getdate() format into database table ??

what can i do ?

give me some suggetions ...
Who is Participating?
John ClaesConnect With a Mentor Senior .Net Consultant & Technical AnalistCommented:
If you send a dateTime from the program to SQL
and you know that the DateTime format for the clients can be different the you can do multiple things.

Easly but on clientSide (My Prefer)
The most easly is at the side of the program use a DataTime.Now.ToString("yyyyMMdd HHmmssffff")
This is automticaly recognized by the SQL Server as a valid DateTime.

using the SQL patern as patern on the Clientside          
Minus point Also Easy but change server patters ==> change Clients)

same Pattern on SQL and ClientSide
Most of the work but is also secure


poor beggar
You can format the date like you want into the insert-statement

insert into Employee(ID,  First_Name, Last_Name, Start_Date)
values ('01','Jason',    'Martin',  to_date('19960725','YYYYMMDD'))

use DateTime.Now itself, it will insert time also..
just be careful of the locality settings in the account used to connect to the SQL box when using the format commands.
 I knew a DBA who rejected scripts and sent out emails cc'd to senior partners stating we hadn't tested the scripts we'd sent him to run.
We replied to all pointing out he'd set his account to run using US date formats while we used UK (seeing as we were a UK based company, using UK servers for UK customers...).

Moral of the story, check the locality settings, and if you can't, set the dateformat in any stored procs you're connecting to.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.