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)
 date format

Author  Topic 

Ex
Posting Yak Master

166 Posts

Posted - 2005-01-16 : 18:29:41
hey all,

i have a string that i want to convert to a date

the string is like so

mystring = 17.03.2003 16:38


SELECT convert(varchar(128),mystring,104)

now i know i can use this method but the problem is
i cant find a datetime format that will suit my string input

104 does dd.mm.yy
but i want the time included as well

any ideas on how i can get this one to work? i am guessing the use of DATEADD but not sure to how creat a empty date so i can use this function

Ex
Posting Yak Master

166 Posts

Posted - 2005-01-16 : 18:31:13
if there is no eazy way let me know cause i can always just select substrings from the input string and put together my own date format that can work


ta
Go to Top of Page

Ex
Posting Yak Master

166 Posts

Posted - 2005-01-16 : 18:44:31
just a side note
at the moment i do this

select SUBSTRING ( '17.03.2003 16:38' , 7 , 4) + '-' +
SUBSTRING ( '17.03.2003 16:38' , 4 , 2) + '-' +
SUBSTRING ( '17.03.2003 16:38' , 1 , 2) + ' ' +
SUBSTRING ( '17.03.2003 16:38' , 12 , 2) + ':' +
SUBSTRING ( '17.03.2003 16:38' , 15 , 2)

Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-01-16 : 18:45:49
Don't ask why, but mine did this...
select convert(datetime,'17.03.2003 16:38',104)
------------------------------------------------------
2003-03-17 16:38:00.000


rockmoose
Go to Top of Page

Ex
Posting Yak Master

166 Posts

Posted - 2005-01-16 : 18:52:30
thats fine that is just getting the milliseconds


I am using this to compaire 2 dates i.e if date in table > inputdate So if the the millseconds are there it wont matter as they will always be 000 so wont effect my code
Go to Top of Page
   

- Advertisement -