Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 convertion of mmddyyhhmmss to datetime format

Author  Topic 

pavan2143
Starting Member

2 Posts

Posted - 2008-05-20 : 08:17:27
Hi,

I want to convert mmddyyhhmmss which is in string format to be converted into datetime format (Ex: dd/mm/yy/hh/mm/ss).
I will be pleased if any one of u respond quickly.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-05-20 : 08:27:19
Is your intention to convert that string to a DATETIME datatype or to leave it as a string and simply re-arrange the characters so that it matches your example format? Since you only have a 2 digit year can we assume that all your dates will be between the years: 1951 and 2050?

Be One with the Optimizer
TG
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-20 : 08:32:14
Your suggested format is NOT a datetime format anywhere in the world.
What are you trying to accomplish?


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-20 : 11:47:07
quote:
Originally posted by pavan2143

Hi,

I want to convert mmddyyhhmmss which is in string format to be converted into datetime format (Ex: dd/mm/yy/hh/mm/ss).
I will be pleased if any one of u respond quickly.


Is this only for displaying? EVen then i dont think this format makes sense.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-05-20 : 12:59:20
[code]DECLARE @DT VARCHAR(12)
DECLARE @SomeDateFormat VARCHAR(17)

SET @DT = 'mmddyyhhmmss'

SET @SomeDateFormat = SUBSTRING(@DT, 3, 2)
+ '/' + SUBSTRING(@DT, 1, 2)
+ '/' + SUBSTRING(@DT, 5, 2)
+ '/' + SUBSTRING(@DT, 7, 2)
+ '/' + SUBSTRING(@DT, 9, 2)
+ '/' + SUBSTRING(@DT, 11, 2)

SELECT @SomeDateFormat[/code]
Go to Top of Page
   

- Advertisement -