I need help parsing string of the following pattern for checkin date and checkout date in SQL
'CheckIn: Thursday, April 05, 2012
CheckOut: Saturday, April 07, 2012'
I tried
select
SUBSTRING([stringToParse], CHARINDEX('Checkin: ', [stringToParse])+9, charindex('<',stringToParse)) as checkin_date,
SUBSTRING([stringToParse], CHARINDEX('CheckOut: ', [stringToParse])+10, LEN([stringToParse])) as checkout_date from xyztable
which works for checkout date but when I use similar approach to parse checkin it returns
'Thursday, April 05, 2012
Chec'
I need to parse checkin date
The third argument to substring() is the length, not the offset. Try this: