Solved

About Datetime type??

Posted on 1998-09-21
2
197 Views
Last Modified: 2010-03-19
I just want to know how to convert varchar type till datetime type (t.ex. 980901 till Sep 1 1998  1:59AM), so that I can use commando Datediff, or may be somebody has better idea?
0
Comment
Question by:ruisun
2 Comments
 
LVL 7

Accepted Solution

by:
spiridonov earned 50 total points
ID: 1090207
you should use  CONVERT function:
CONVERT(datetime,your_variable)
0
 

Expert Comment

by:SpaarQ
ID: 1090208
Try this:

DECLARE @mydate VARCHAR(10)
SELECT    @mydate = "980901"

SELECT @mydate = CONVERT(DATETIME, @mydate)


Result is:

Sep 1 1998 12:00AM

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

828 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