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
Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

829 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