Cannot write DateTime with Kind=Local to PostgreSQL type 'timestamp with time zone', only UTC is supported means a DateTime.Now reached a column that stores moments in time. Save DateTime.UtcNow, or convert the value to UTC before SaveChanges, and the insert goes through.

EF Core with Npgsql maps a DateTime property to timestamp with time zone (timestamptz), and for that type Npgsql accepts only values whose Kind is Utc. Fix the value where the time enters your code, not the database.

The error

Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
 ---> System.ArgumentException: Cannot write DateTime with Kind=Local to PostgreSQL type 'timestamp with time zone', only UTC is supported. Note that it's not possible to mix DateTimes with different Kinds in an array, range, or multirange. (Parameter 'value')
   at Npgsql.Internal.Converters.DateTimeConverterResolver`1.Get(DateTime value, Nullable`1 expectedPgTypeId, Boolean validateOnly)

A time parsed from a string without an offset fails the same way, with Kind=Unspecified in place of Kind=Local.

Why it happens

A PostgreSQL timestamptz is a point in time, stored as UTC. A .NET DateTime carries no offset, only a Kind flag: Utc, Local (the clock of whichever machine runs the code) or Unspecified. To store a local value, Npgsql would have to guess its offset from the server's time zone, and a web server's zone is rarely the user's. Rather than guess, it refuses anything that is not already UTC, and the refusal surfaces from SaveChanges wrapped in a DbUpdateException.

Code written for SQL Server often meets this on its first insert against PostgreSQL: datetime2 has no time zone at all, so DateTime.Now was never questioned there.

The fix

db.Appointments.Add(new Appointment { PatientName = "Maria Garcia", StartsAt = DateTime.UtcNow });
await db.SaveChangesAsync();

When the value is a local time typed into a form, name the zone it belongs to and convert it:

var clinicZone = TimeZoneInfo.FindSystemTimeZoneById("Europe/Madrid");
var local = DateTime.Parse("2026-10-01T09:30:00");
var startsAt = TimeZoneInfo.ConvertTimeToUtc(local, clinicZone);
db.Appointments.Add(new Appointment { PatientName = "Maria Garcia", StartsAt = startsAt });

That saved 2026-10-01 07:30:00+00, which is 09:30 in Madrid, even though the machine running it was set to India time. Convert back to the viewer's zone when you display it.

If the column really is a wall-clock value with no zone, such as a clinic's opening hour, map it to timestamp without time zone; that column accepted DateTime.Now and stored the local time as written:

b.Entity<Visit>().Property(v => v.ArrivedAt).HasColumnType("timestamp without time zone");

The escape hatch is Npgsql's legacy switch, set before anything else runs. It still exists in Npgsql 10 and it did make DateTime.Now save, but only because it maps every DateTime in the model to timestamp without time zone: a fresh database got different column types. Treat it as a stopgap for an old codebase, not a fix.

AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);

How it was reproduced

A minimal API from dotnet new web with Microsoft.EntityFrameworkCore 10.0.12 and Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3, an Appointment entity with a DateTime StartsAt, and a table created by EnsureCreated. A POST that saved DateTime.Now returned 500 with the error above; the same POST with DateTime.UtcNow saved. .NET SDK 10.0.401 on Windows, PostgreSQL 18.4 in the postgres:18 Docker image.

Frequently asked

Why does Npgsql only accept UTC DateTime for timestamp with time zone?
A timestamptz column stores an instant in UTC. A DateTime with Kind Local or Unspecified has no offset, so Npgsql would have to guess one from the server's time zone. It refuses instead, and you convert to UTC yourself with DateTime.UtcNow, ToUniversalTime or TimeZoneInfo.ConvertTimeToUtc.
Should I use EnableLegacyTimestampBehavior to fix the Kind=Local error?
Only as a temporary measure. The switch still works in Npgsql 10, but it changes the default mapping of every DateTime property to timestamp without time zone, so new tables and migrations come out different. Saving UTC values is the lasting fix.
How do I store a local time in PostgreSQL with EF Core?
If the value is a moment, convert it to UTC before saving and back to the viewer's zone for display. If it is a wall-clock time with no zone, such as an opening hour, map the property to timestamp without time zone with HasColumnType; that column accepts DateTime.Now as written.

More decoded errors in the Fixes category. For choosing between the two timestamp types when a schema moves from SQL Server, see the timestamp section of the data types translation table.