Solved

About Datetime type??

Posted on 1998-09-21
2
204 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
[X]
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
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

617 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