Skip to content

DateTime paramter with UTC value is converted to Local datetime #2881

Closed

Description

@sandeep-eroad

The issue

The DateTime value should be stored as-is and not converted to Local datetime.

Further technical details

Npgsql version: 4.1.3.1
PostgreSQL version: 11.6
Operating system: Windows 10
NPGSqlTest.zip

Activity

  1. YohDeadfall commented on Mar 2, 2020

    @YohDeadfall
    Contributor

    Duplicate of #2209.

    The driver send any DateTime as timestamp and DateTimeOffset as timestamptz. This was done to avoid another confusion with local time conversion.

    If you have a timestamptz column use the corresponding CLR type to avoid server side conversion.

  2. sandeepc24 commented on Mar 2, 2020

    @sandeepc24

    If you look at the sample I attached the table is defined as

        create table public.test
        (
            id bigint not null constraint test_pkey primary key,
            modified timestamp
        );
    

    and the code inserting record is

                    var cmd = new NpgsqlCommand("insert into test values (1, @Modified)", con);
                    cmd.Parameters.AddWithValue("Modified", DateTime.UtcNow);
    

    this should work as per your explanation. I don't see why it doesn't.

    My postgres timezone is Pacific/Auckland, is this causing the conversion?

  3. YohDeadfall commented on Mar 2, 2020

    @YohDeadfall
    Contributor

    Okay, will take a deeper look later today.

  4. YohDeadfall commented on Mar 3, 2020

    @YohDeadfall
    Contributor

    Checked the example, but wasn't able to reproduce the issue. The returned value was the same as I passed as a parameter. Please check that you're not using timestamptz anywhere.

  5. sandeepc24 commented on Mar 4, 2020

    @sandeepc24

    @YohDeadfall - I have double checked, I am not using timestamptz anywhere.

  6. sandeepc24 commented on Mar 4, 2020

    @sandeepc24

    But, after changing my postgres timezone to UTC the test app works as expected.

  7. YohDeadfall commented on Mar 5, 2020

    @YohDeadfall
    Contributor

    Sounds strange since PostgreSQL converts timestamp with time zone only. How are you checking which value is stored in the database?

  8. sandeepc24 commented on Mar 5, 2020

    @sandeepc24

    Using PGAdmin 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions