I am trying to convert
@string='25/05/2016 09:00'
to 2016-05-25 09:00
.
@string
is concatenation of @string2='25/05/2016'
and @string3='09:00'
When I try to do this using
CONVERT(datetime, '25/05/2016 09:00')
I get the following error
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
Please help, thanks.
3条答案
按热度按时间flvtvl501#
Try this:
The
convert
method takes 3 arguments: The first is the target data type, the second is the expression to convert, and the third is the style. In this case, 103 stands for British or French date format, which isdd/mm/yyyy
.Result:
2016-05-25 09:00:00.0000000
(datetime2
)mutmk8jj2#
thanks marc_s for putting my query in the right format.
I tried this and got the expected result, please advise if there is any other optimal way, thanks
kq0g1dla3#
add this statement before convert
so query look like this