<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/c-tip-create-correct-datetimes-with-datetimekind-eafn6f8rb" -->

---
title: C# tip: create correct DateTimes with DateTimeKind
description: Creating a plain DateTime without specifying DateTimeKind causes inconsistent results when calling ToUniversalTime and ToLocalTime, because .NET assumes Local...
canonical: https://daily.dev/posts/c-tip-create-correct-datetimes-with-datetimekind-eafn6f8rb
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: C# tip: create correct DateTimes with DateTimeKind | daily.dev
og:description: Creating a plain DateTime without specifying DateTimeKind causes inconsistent results when calling ToUniversalTime and ToLocalTime, because .NET assumes Local...
og:url: https://daily.dev/posts/c-tip-create-correct-datetimes-with-datetimekind-eafn6f8rb
og:image: https://api.daily.dev/og/posts/eAFN6F8RB.png
og:image:alt: C# tip: create correct DateTimes with DateTimeKind
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# C# tip: create correct DateTimes with DateTimeKind

**[Code4IT](https://daily.dev/sources/code4it)** · 2 min read · 0 upvotes · 0 comments

## Summary

Creating a plain DateTime without specifying DateTimeKind causes inconsistent results when calling ToUniversalTime and ToLocalTime, because .NET assumes Local or UTC respectively depending on the method. Always specifying DateTimeKind.Utc (or Local) when constructing a DateTime avoids this discrepancy, since the three possible values are Unspecified, Utc, and Local.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.code4it.dev/csharptips/datetimekind>

## Questions this post answers

### why does ToUniversalTime() give a different result than ToLocalTime() on the same C# DateTime value

The difference happens because a DateTime created without specifying DateTimeKind defaults to Unspecified, and ToUniversalTime assumes it is Local time while ToLocalTime assumes it is UTC. For example, a DateTime of 2020-01-01 00:30:00 becomes 2019-12-31 23:30:00 with ToUniversalTime but 2020-01-01 01:30:00 with ToLocalTime in a UTC+1 zone.

_Developers debugging timezone drift in C# can find similar date-handling gotchas curated on daily.dev._

### how do I create a DateTime in C# that stays consistent across ToUniversalTime and ToLocalTime calls

Specify the DateTimeKind parameter explicitly when constructing the DateTime, such as new DateTime(2020, 1, 1, 0, 30, 0, DateTimeKind.Utc). This makes the value unambiguous, so calling ToUniversalTime or ToLocalTime on it returns the same date and time instead of shifting by an hour or more based on assumed time zone.

_daily.dev surfaces practical .NET tips like this for developers hardening date logic against timezone bugs._

### what are the possible values of the DateTimeKind enum in C#

DateTimeKind has exactly three possible values: Unspecified, Utc, and Local. Unspecified is the default when no kind is given during DateTime construction, and it is this ambiguity that causes ToUniversalTime and ToLocalTime to produce inconsistent, timezone-shifted results.

_Track small but critical .NET API details like this on daily.dev while building reliable date handling._

## Similar posts on daily.dev

- [Stop Pretending TimeProvider Doesn't Exist — Daily DevOps & .NET](https://daily.dev/posts/stop-pretending-timeprovider-doesn-t-exist-daily-devops-net-8lez0ga1i) · We Are .NET · 21 upvotes · 1 comments
- [Dating in Hungarian](https://daily.dev/posts/dating-in-hungarian-zgmrw0o1s) · The Daily WTF · 7 upvotes · 0 comments
- [10 best practices for timestamps and time zones in databases](https://daily.dev/posts/10-best-practices-for-timestamps-and-time-zones-in-databases-xhfzsegaw) · Tinybird · 2 upvotes · 1 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/c-tip-create-correct-datetimes-with-datetimekind-eafn6f8rb)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"C# tip: create correct DateTimes with DateTimeKind","url":"https://daily.dev/posts/c-tip-create-correct-datetimes-with-datetimekind-eafn6f8rb","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/c-tip-create-correct-datetimes-with-datetimekind-eafn6f8rb"},"datePublished":"2026-10-04T13:06:53.769Z","dateModified":"2026-10-04T13:16:26.434Z","description":"Creating a plain DateTime without specifying DateTimeKind causes inconsistent results when calling ToUniversalTime and ToLocalTime, because .NET assumes Local...","image":"https://media.daily.dev/image/upload/s--ZrL_HSsR--/f_auto/v1722860399/public/Placeholder%2006","thumbnailUrl":"https://media.daily.dev/image/upload/s--ZrL_HSsR--/f_auto/v1722860399/public/Placeholder%2006","isAccessibleForFree":true,"articleSection":"Code4IT","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Code4IT","logo":"https://media.daily.dev/image/upload/s--OaaG4G10--/f_auto,q_auto/v1791119049/logos/code4it?_a=BAMAMicg0","url":"https://daily.dev/sources/code4it"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/c-tip-create-correct-datetimes-with-datetimekind-eafn6f8rb","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net,c#","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Code4IT","item":"https://daily.dev/sources/code4it"},{"@type":"ListItem","position":3,"name":"C# tip: create correct DateTimes with DateTimeKind"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/c-tip-create-correct-datetimes-with-datetimekind-eafn6f8rb#faq","mainEntity":[{"@type":"Question","name":"why does ToUniversalTime() give a different result than ToLocalTime() on the same C# DateTime value","acceptedAnswer":{"@type":"Answer","text":"The difference happens because a DateTime created without specifying DateTimeKind defaults to Unspecified, and ToUniversalTime assumes it is Local time while ToLocalTime assumes it is UTC. For example, a DateTime of 2020-01-01 00:30:00 becomes 2019-12-31 23:30:00 with ToUniversalTime but 2020-01-01 01:30:00 with ToLocalTime in a UTC+1 zone. Developers debugging timezone drift in C# can find similar date-handling gotchas curated on daily.dev."}},{"@type":"Question","name":"how do I create a DateTime in C# that stays consistent across ToUniversalTime and ToLocalTime calls","acceptedAnswer":{"@type":"Answer","text":"Specify the DateTimeKind parameter explicitly when constructing the DateTime, such as new DateTime(2020, 1, 1, 0, 30, 0, DateTimeKind.Utc). This makes the value unambiguous, so calling ToUniversalTime or ToLocalTime on it returns the same date and time instead of shifting by an hour or more based on assumed time zone. daily.dev surfaces practical .NET tips like this for developers hardening date logic against timezone bugs."}},{"@type":"Question","name":"what are the possible values of the DateTimeKind enum in C#","acceptedAnswer":{"@type":"Answer","text":"DateTimeKind has exactly three possible values: Unspecified, Utc, and Local. Unspecified is the default when no kind is given during DateTime construction, and it is this ambiguity that causes ToUniversalTime and ToLocalTime to produce inconsistent, timezone-shifted results. Track small but critical .NET API details like this on daily.dev while building reliable date handling."}}]}
```

