Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now