?
Solved

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

Posted on 2011-02-21
4
Medium Priority
?
873 Views
Last Modified: 2012-05-11
i have to insert time into sql server 2008 table , but it has format datetime.now() and i have to insert getdate() format into database table ??

what can i do ?

give me some suggetions ...
0
Comment
Question by:Parth48
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 34942155
You can format the date like you want into the insert-statement

Example:
insert into Employee(ID,  First_Name, Last_Name, Start_Date)
values ('01','Jason',    'Martin',  to_date('19960725','YYYYMMDD'))
0
 
LVL 10

Accepted Solution

by:
John Claes earned 2000 total points
ID: 34942237
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

reagards

poor beggar
0
 
LVL 7

Expert Comment

by:kovilpattiBalu
ID: 34942276
hi,

use DateTime.Now itself, it will insert time also..
0
 
LVL 7

Expert Comment

by:mr_nadger
ID: 34950717
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.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question