Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to convert ddmmyy into SQL datetime

Posted on 2008-11-13
3
Medium Priority
?
1,768 Views
Last Modified: 2012-05-05
Hello,

I have an IVR which takes in DTMF values for a date in the format ddmmyy.

I then want to update a date field with those values - how do I go about convert the string into a datetime field?  I'm finding I can't use Convert(Datetime....  because it is expecting the input in a different format.

Likewise if I take in, for example, 1450 to represent a time, how do I get that into a table field to log the time?

Thanks in advance....
0
Comment
Question by:catherinelouise
3 Comments
 
LVL 4

Expert Comment

by:Mitzs
ID: 22948499
try this
declare @dt as varchar(6)
set @dt = '141108'
select cast(substring(@dt,1,2) + substring(@dt,3,2) + substring(@dt,5,2) as datetime)
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 22948508
you have to work the string a bit:

DECLARE @data VARCHAR(6)
SET @data = '131108'
SELECT @data, CONVERT(datetime, LEFT(@data, 2) + '.' + SUBSTRING(@data,3,2) + '.' + SUBSTRING(@data, 5,2), 4) date_value

Open in new window

0
 
LVL 5

Author Closing Comment

by:catherinelouise
ID: 31516310
Sweeet - thanks angelll
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 ?
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
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…
Suggested Courses

572 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