473,322 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

converting string to date

Hello,

I try to convert a pseudo datetime string into a date. In Oracle I can do
to_date( MyDate, 'yyyymmddhh24miss' ); how I can do this with MS SQL ?

thanks and regards
Mark
Aug 12 '05 #1
2 47056
See CONVERT() in Books Online - it supports a number of different
formats, although not the exact one you've mentioned above. You might
need to look at modifying the string before using CONVERT() - see
"String Functions" in Books Online, or you could also consider doing
that in your client application.

Simon

Aug 12 '05 #2
On Fri, 12 Aug 2005 14:17:57 +0200, Mark wrote:
Hello,

I try to convert a pseudo datetime string into a date. In Oracle I can do
to_date( MyDate, 'yyyymmddhh24miss' ); how I can do this with MS SQL ?

thanks and regards
Mark


Hi Mark,
The easiest way is to use string functions to convert your date to the
unambiguous ISO-standard yyyy-mm-ddThh:mm:ss format, then cast to
datetime:

DECLARE @DateString char(14)
SET @DateString = '20050812204332'
SELECT CAST(SUBSTRING(@DateString, 1, 4) + '-'
+ SUBSTRING(@DateString, 5, 2) + '-'
+ SUBSTRING(@DateString, 7, 2) + 'T'
+ SUBSTRING(@DateString, 9, 2) + ':'
+ SUBSTRING(@DateString, 11, 2) + ':'
+ SUBSTRING(@DateString, 13, 2) AS datetime)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Aug 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ree32 | last post by:
I am having problems with Date Strings when using VS.net method of converting an XML document to a dataset. I need the the date nodes to be of date type. As I am loading the Dataset to a...
8
by: Mika M | last post by:
Is there better way to convert integer type date into DateTime type date as doing like code below? Dim intDate As Integer = 20051019 Dim dte As DateTime = New DateTime( _...
3
by: NateM | last post by:
How do I convert any given date into a milliseconds value that represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT? Is there an easy way to do this like...
2
by: XML newbie: Urgent pls help! | last post by:
Does anyone have a snippet of code that will convert a string to a long array? I've nearly smashed my head against the wall trying to figure this out. I'm Using vb.net 2005 Pls reply asap. I...
12
by: Rob Meade | last post by:
Hi all, Ok - I've come from a 1.1 background - and previously I've never had any problem with doing this: Response.Write (Session("MyDate").ToString("dd/MM/yyyy")) So, I might get this for...
9
by: Alok yadav | last post by:
i am using a webservice in which a method is serach. i use this method which accept a argument of date type in dd/MM/yyyy formate. i have a textbox which accept the date from the user, when i...
6
by: marc | last post by:
hi im trying to convert Date() into a unix timestamp so i can stick the result into a mysql db, please help!
3
by: zshenk | last post by:
I need help converting dates. Currently, I have several tables and databases that use the format 1/20/2007. I have a table right now that uses the 20070120 format, and I was hoping that someone...
2
by: Brian Parker | last post by:
I am beginning to work with VB2005.NET and I'm getting some problems with string formatting converting an application from VB6. VB6 code:- sTradeDate = Format(pArray(4,i Record), "mmddyy") ...
3
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.