Solved

How do i cast date format in Sql Server ?

Posted on 2016-11-03
9
34 Views
Last Modified: 2016-11-03
Hi Experts ,

Am trying to insert the date filed value as
09-11-2016 11:00 PM
and sql server is throwing error as Out of range exception . How do i cast the date as (dd-mm-yyyy) format .
0
Comment
Question by:karthik80c
9 Comments
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 41872144
For inserts the best thing is using the format YYYYMMDD. So in your case '20161109'.
You don't need the time, do you?
0
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 250 total points
ID: 41872168
>How do i cast the date as (dd-mm-yyyy) format .
Just to clarify, dates are not stored in a specific format, so the storage answer is you don't convert (so Vitor's answer above works).  

If you wish to display the date in dd-mmm-yy format, then use convert(varchar, your_data_here ,5).   For a handy reference check out SQL Server Date Styles (formats) using CONVERT()
2
 

Author Comment

by:karthik80c
ID: 41872270
Hi Vitor Montalvão,

Yes i need the time too . what should be the time format i should go for
0
 

Author Comment

by:karthik80c
ID: 41872277
Yeah sure Jim I will try with that
0
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.

 
LVL 45

Accepted Solution

by:
Vitor Montalvão earned 250 total points
ID: 41872286
Yes i need the time too . what should be the time format i should go for
Just add the time to the date separating them with a space. Example: '20161109 11:00PM'.
1
 

Author Comment

by:karthik80c
ID: 41872294
Thanks Vitro . You are the Man of SQL Buddy
0
 

Author Closing Comment

by:karthik80c
ID: 41872304
Got the Answers Thanks To Experts
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 41872306
Best is to use 24-hour clock:

'20161109 23:00'

It's shorter and 100% unambiguous.
3
 

Author Comment

by:karthik80c
ID: 41872312
Thanks Scoot
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

757 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

22 Experts available now in Live!

Get 1:1 Help Now