Get query result by converting Date Time field to local Time zone

Asked

Viewed 282 times

1

I have a table in the sql server database that has the following Datahora field where

I have data included in this following format:

 DataHora
 2015-04-20 17:43:04.000

this time is not in the format of our time zone.

I need to make a query that in the result show me the result Converted to our Time zone

I have the following query:

  select Serial, 
 Latitude,
 Longitude,
 DataHora as DataHora
 from [CheckPoint] where DataHora between SWITCHOFFSET (CONVERT(datetimeoffset, '2015-04-22 10:00'),'-03:00')and SWITCHOFFSET (CONVERT(datetimeoffset, '2015-04-22 11:00'),'-03:00')
 and serial='113394' order by DataHora

Would there be any easier way to get these converted data ? in my query I am passing a certain date and is converting to the indicated zone ie what I type The time will be -3. then I won’t get concrete data of the given time.

Doubt: I need to get this formatted data to our time zone,

  • Are you only using SQL or are you using another language to construct the parameters?

  • Cara c#! I am showing only the query,but I have a method in my application where I send by parameter to Datahora

  • @Hansmiller has already found the solution?

  • What’s wrong with using the SWITCHOFFSET?

1 answer

-1

See if this instruction helps:

Commando:

SELECT CONVERT(varchar(10),CAST('2015-04-20 17:43' AS datetime2),103)+' '+ CONVERT(varchar(8),CAST('2015-04-20 17:43' AS datetime2),114) AS 'data'

Upshot:

20/04/2015 17:43:00

Browser other questions tagged

You are not signed in. Login or sign up in order to post.