简体   繁体   中英

Getting invalid datetime values from WCF service

I have a WCF service and a windows application, both on different time-zones. Now this windows application saves and retrieve data through WCF service.

When i do a bulk insert for a table having a column as logtime of datatype as datetime, i am able to save this local datetime in the database, but when i try to retrieve this table, it gives all wrong values of logtime column.

Found many similar question on SO, but i can't implement UTC time, since the table i am referring to contains a thousand records, which keeps updating every 5-10 seconds.

Is there any way to stop this automatic datetime conversion done by WCF service.

Please guide.

What does this mean: "it gives all wrong values of logtime column." Is the time the local time of the database server? And that's not what you want?

I'm assuming you want the logtime column to be the time zone of the client machine. Is that right? And I'm also assuming, since it's not specified, that you're setting the logtime column using the default value of GetDate() within SQL Server. I'm also assuming, since it's not specified, that you're using SQL Server.

If you want to use the time zone of the client, then you have a few options:

  1. Change the time zone of the database server to the same time zone as the client machine.
  2. Pass the time, to the WCF service, as a parameter. (I'm assuming the WCF service is running on a server in the same time zone as the database server.)
  3. Leave it as is, but convert to the right time zone when retrieving the data.

There may be some more options, but it would be helpful if you clarified the assumptions I made.

What do you mean by this: "automatic datetime conversion done by WCF service?" Is it using its local time zone for the time? If so, then you'll need to have it accept a time, instead of determining it itself. Perhaps you should show some code. That would be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM