Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

About Datetime type??

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
ruisun
Asked:
ruisun
1 Solution
 
Victor SpiridonovCommented:
you should use  CONVERT function:
CONVERT(datetime,your_variable)
0
 
SpaarQCommented:
Try this:

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

SELECT @mydate = CONVERT(DATETIME, @mydate)


Result is:

Sep 1 1998 12:00AM

0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Tackle projects and never again get stuck behind a technical roadblock.
Join Now