August 16, 2007 at 8:14 am
Hello friends , i need your help, i got a problem to try convert a data varchar into datetime, well i need to convert a field of a table which is formatted in 'ddmmyyy'
for example
SELECT convert(datetime,'30122006',105)
and i got the next error
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
if the datas of field would be separated by a '-' for example '30-12-2006' I have not the problem the query is executed successful but the datas have not the separator sign, i am think to aggregate it , do you know another idea to solve my problem???
Thanks for read me and excuse me my bad english Cheers
August 16, 2007 at 8:28 am
When trying to convert the character value '30122006', sql is expecting the value to represented in the format yyyymmdd. I tried your sample and got the same error. adding the '-' allowed me to properly convert the date, as did reformating the string to yyyymmdd format.
You may need to reformat your data before doing the conversion.
August 16, 2007 at 8:33 am
This works. But be careful in your format as Lynn stated.
SELECT convert(datetime,'20061230',105)
August 16, 2007 at 8:34 am
yes, that seems the only solution, ok i will resign myself to reformate my data
Thank for read me friend
August 16, 2007 at 8:39 am
SELECT CONVERT(DATETIME,STUFF(STUFF('30122006', 3, 0, '-'), 6, 0, '-'), 105)
Regards,
gova
August 16, 2007 at 9:01 am
Thanks i will try it
August 16, 2007 at 9:12 am
gova, so that's why i had trouble using STUFF when I was trying to come up with a conversion solution. Thanks!
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy