Skip to content

Problematic timezone conversion with parameter of DateTime with Kind=UTC #105

@goran-subotic

Description

@goran-subotic

Can someone please explain behaviour below? I'm not sure if I'm doing something wrong or this is a bug in ClickHouseClient (looks like it).

I'll explain the problem with additional timezone conversion that happens when I pass DateTime object value with Kind=UTC from .NET 9 app:

=====

  1. CH DB:
    SELECT timezone(); Europe/Budapest +1

  2. CH server timezone: Europe/Budapest +1

  3. Column definition: DateTime64(3, 'UTC')

  4. .NET 9 app timezone: Europe/Budapest +1

My .NET 9 app accesses the DB and passes DateTime parameter in WHERE clause like this (DateTimeOffset.UtcDateTime):

command.Parameters.Add(new ClickHouseParameter
{
ParameterName = "StartTime",
Value = startTime.UtcDateTime
});

UTC time: 13:30
Local (Budapest) time: 14:30
Value of startTime parameter 13:30+00:00 (Type=DateTimeOffset)
startTime.UtcDateTime returns DateTime with Kind=UTC

Problem:

  • If I execute command with this parameter ClickHouseClient driver will ignore the Kind parameter and perform another timezone conversion, therefore it will execute SELECT with one extra hour removed and I will get results with last record set to 12:30 UTC instead of 13:30 UTC (which should be local 14:30 Budapest)

  • If I just set the parameter as:

command.Parameters.Add(new ClickHouseParameter
{
ParameterName = "StartTime",
Value = startTime
});

UTC time: 13:30
Local (Budapest) time: 14:30
Value of startTime parameter 13:30+00:00 (Type=DateTimeOffset)

Parameter value will be properly passed and I will get records with last record set to 13:30 UTC which is OK.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions