Search code examples
c#postgresqlentity-frameworkc#-4.0pgadmin-4

How to insert DateTime value in PostgreSQL from C#


I want to insert the DateTime value in PostgreSQL from C# I have fields in my model like this

       [DataType(DataType.DateTime)]
       public DateTime ApplicationDate { get; set; }

       [Column(TypeName = "jsonb")]
      public StudentInformationtApp StudentInformation { get; set; }

The field in JsonB model

public DateTime AwaitingDate { get; set; }

I am getting the value of ApplicationDate from API is like this 2021-04-02 08:05:45 but when I check in PostgreSQL DB it shows only date 2021-04-02 00:00:000 and for the jsonb fields AwaitingDate it stores like this 2021-04-02T08:05:45 What is a T? can I store the exact same value as it comes from my API. If it comes like this 2021-04-02 08:05:45 store like this 2021-04-02 08:05:45 only

I am using <PackageReference Include="Npgsql.Bulk" Version="0.9.0" This package for the Bulk insert/Update in PostgreSQL DB https://www.nuget.org/packages/Npgsql.Bulk


Solution

  • Are you sure you are using DateTime format in your db for ApplicationDate? It seems like you're only storing a date, hence the time being at zero. T is just a separator between the date and the time. I don't see why this is a problem, because you'll probably format the date before showing (after casting it to DateTime).