Solved

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

Posted on 2011-02-21
4
855 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 500 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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