0

Need to get the date part from column Start_DateTime (varchar data type) which is having data like '06/04/19 10:44 AM CDT' , '06/10/19 11:56 AM EDT' and need to convert the time zone to CST time zone

I have a user defined function dbo.fn_UTCtoCST that will convert the time zone but am trying to combine all this in a select query to get the desired result

SELECT 
            Start_DateTime
           ,Inspector
           ,Status
           ,Distance
           ,Location
from XYZ
  • Never store timestamp values in a `varchar` column. The problem you have now, is a direct result of using the wrong data type –  Jun 11 '19 at 04:04
  • You may refer to this question: https://stackoverflow.com/questions/207190/sql-server-string-to-date-conversion – Flavio Francisco Jun 11 '19 at 07:53

1 Answers1

0

If your function is scalar value function(returning one value) then this might will work for you.

select * 
from A 
  cross apply dbo.fn_UTCtoCST(date)  cstdate.
Mak
  • 1,068
  • 8
  • 19
  • Why the apply? If the function is a scalar function you can use it directly in the SELECT list: `select dbo.fn_UTCtoCST(date) from a` –  Jun 11 '19 at 04:05
  • I meant to say function should return one row(one value). – Mak Jun 11 '19 at 04:08
  • There is a huge difference between "one row with one column" and a "single (scalar) value" –  Jun 11 '19 at 04:09
  • One row one column that means single value i guess. https://www.c-sharpcorner.com/UploadFile/898089/how-to-create-scalar-value-function-in-sql-server-2012/ – Mak Jun 11 '19 at 04:27