Solved

How do i cast date format in Sql Server ?

Posted on 2016-11-03
9
63 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 49

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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:karthik80c
ID: 41872277
Yeah sure Jim I will try with that
0
 
LVL 49

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:Scott Pletcher
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

713 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