string to datetime conversion using date parameters in SSRS
Hello, I have a database field that I am pulling that is type string, but the format of each value is mm/dd/yyyy. I want to convert this to a datetime format (minus the time) so that i can compare this value to a parameter date range (begin date and end date) that are type datetime so that i can use the calendar control in my report. i've tried in my select statement to use select.....convert(datetime, stringfieldname, 101), but I get an error that says "Conversion failed when converting datetime to character string". I am also open to converting the datetime parameters to strings to do the comparison, but not sure the best way to do this either. thanks!
October 19th, 2010 9:44pm

i believe your string field is not in a proper tsql date format to directly convert it to a date you can try something like this to first convert your string into a workable format: select convert(datetime, substring(stringfieldname, 7,4) + '-' + substring(stringfieldname, 1,2) + '-' + substring(stringfieldname, 4,2), 101) its a shame tsql doesnt have an equivalent to_date function in Oracle then you can simple do to_date(stringfieldname, 'mm/dd/yyyy')
Free Windows Admin Tool Kit Click here and download it now
October 19th, 2010 11:21pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics