May 23, 2016 at 11:34 am
Trying to convert datetime to varchar(10), typical stuff. Only problem is, it's not working. This first example works fine:
select top 1 convert(varchar(10),createdon, 101)
from tracking
But when I have it - the same way - in another query, it returns it as a datetime value.
Id_OrderNumber_ReferralNumber=lb.orderno,
Id_ShipDate=convert(varchar(10),tr.createdon,101),
Id_OrderDate=convert(varchar(10),ot.createdon,101),
Id_FirstPatientShipDate=convert(varchar(10),fs.FirstShip,101),
Any ideas?
Randy
May 23, 2016 at 11:45 am
what does "not working" mean to you? you did not mention any errors, and convert(varchar will return a string, albeit maybe a string that looks like a date, but it cannot return datetime.
if you assign it or insert it into a datetime column, it might implicitly convert from string to date time, is that what you are seeing?
Lowell
May 23, 2016 at 11:48 am
Remember that CONVERT won't reformat a string. The column needs to be a date/time data type to allow CONVERT apply the format code.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply