C# File GetCreationTimeUtc() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
System.IO

Definition

In C#, File.GetCreationTimeUtc() returns the creation time of a file: the moment it was created. The answer is a DateTime in UTC (Kind is Utc).

UTC does not change with the time zone or daylight saving, so it is the best form for logs, comparisons, and data you send to other machines. For a missing file the method does not throw; it returns 1601-01-01 00:00 UTC, so check File.Exists first. The local form is GetCreationTime.

This is a static method of System.IO.File. Call it as File.GetCreationTimeUtc(...); there is no new File(). For an object that remembers one file, see FileInfo.

Syntax

Pass the path of an existing file and store the DateTime that comes back.

C#
string path = Path.Combine(Path.GetTempPath(), "codetofun-getcreationtimeutc.txt");
File.WriteAllText(path, "demo");

DateTime when = File.GetCreationTimeUtc(path);

Console.WriteLine(when.Kind);   // Utc
CallWhat it does
File.GetCreationTimeUtc(path)Returns the creation time as UTC.
File.GetCreationTimeUtc(path).ToString("yyyy-MM-dd HH:mm")Formats the value as text with a fixed pattern.
File.GetCreationTimeUtc(missingPath)No exception. Returns 1601-01-01 UTC.

FileInfo.CreationTimeUtc gives the same value as a property. A FileInfo may keep an older value until you call Refresh(), while File.GetCreationTimeUtc asks the file system every time.

Library declarations
C#
public static DateTime GetCreationTimeUtc(string path);

Parameters

ParameterDescription
pathThe file to read the time from. It may be absolute or relative.

Return Value

Return ValueDescription
DateTimeThe creation time, with Kind set to Utc. For a missing file the value is January 1, 1601 UTC.

C# Examples

Example 1 — Read a UTC Creation Time You Set Yourself

Set a fixed UTC value, read it back, and print its text and its kind.

C#
using System;
using System.IO;

class Program {
    static void Main() {
        string root = Path.Combine(Path.GetTempPath(), "codetofun-file-getcreationtimeutc");
        if (Directory.Exists(root)) Directory.Delete(root, true);
        Directory.CreateDirectory(root);

        string path = Path.Combine(root, "stamp.txt");
        File.WriteAllText(path, "demo");

        File.SetCreationTimeUtc(path, new DateTime(2026, 1, 15, 9, 30, 0, DateTimeKind.Utc));

        DateTime created = File.GetCreationTimeUtc(path);
        Console.WriteLine(created.ToString("yyyy-MM-dd HH:mm"));
        Console.WriteLine(created.Kind);

        Directory.Delete(root, true);
    }
}

How It Works

  1. Set UTC on purpose. The value has DateTimeKind.Utc, so the file receives exactly 09:30 UTC, whatever the time zone of your computer.
  2. Read it back unchanged. GetCreationTimeUtc returns the same wall clock text on every machine. That is the big benefit of the Utc form.
  3. The kind is Utc. The last line confirms that the returned DateTime is marked as UTC, so later conversions know where it started.

Example 2 — The Default Value for a Missing File

Compare the result for a missing file with the Windows file time zero.

C#
using System;
using System.IO;

class Program {
    static void Main() {
        string root = Path.Combine(Path.GetTempPath(), "codetofun-file-getcreationtimeutc-missing");
        if (Directory.Exists(root)) Directory.Delete(root, true);
        Directory.CreateDirectory(root);

        string missing = Path.Combine(root, "nothing.txt");

        DateTime created = File.GetCreationTimeUtc(missing);

        Console.WriteLine(created.Year);
        Console.WriteLine(created == DateTime.FromFileTimeUtc(0));

        Directory.Delete(root, true);
    }
}

How It Works

  1. No file, no error. nothing.txt does not exist, yet the call returns a value and does not throw.
  2. The value is 1601. It prints 1601 because this is the zero point of the Windows file time system, on every operating system.
  3. Prove it. DateTime.FromFileTimeUtc(0) builds that same moment, so the comparison prints True. A date this old is a good sign that the file was missing.

Example 3 — Work Out the Age of a File in Days

Use a fixed now so the answer is the same on every run.

C#
using System;
using System.IO;

class Program {
    static void Main() {
        string root = Path.Combine(Path.GetTempPath(), "codetofun-file-getcreationtimeutc-age");
        if (Directory.Exists(root)) Directory.Delete(root, true);
        Directory.CreateDirectory(root);

        string path = Path.Combine(root, "old.txt");
        File.WriteAllText(path, "demo");

        DateTime made = new DateTime(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        DateTime now = new DateTime(2026, 1, 11, 0, 0, 0, DateTimeKind.Utc);
        File.SetCreationTimeUtc(path, made);

        double days = (now - File.GetCreationTimeUtc(path)).TotalDays;
        Console.WriteLine(days);
        Console.WriteLine(days > 7);

        Directory.Delete(root, true);
    }
}

How It Works

  1. A pretend today. The program sets its own now instead of using DateTime.UtcNow, which makes the printed number the same on every run.
  2. Subtract two DateTime values. now - created gives a TimeSpan, and TotalDays turns it into the number of days, 10.
  3. A cleanup rule. The comparison days > 7 is the kind of test used to find files older than a week. In real code use DateTime.UtcNow and the same UTC subtraction.

Frequently Asked Questions

A DateTime with the creation time of the file, as UTC (Kind is Utc).
Use it for logs, comparisons, and data you store or send. UTC has no time zone or daylight-saving shifts, so two machines agree on the value.
It does not throw. It returns January 1, 1601 UTC. Check File.Exists first when a missing file is possible.
Many Linux file systems do not store a creation time, or .NET cannot read or change it there. The value may be approximated from other times. For portable code use the last write time, and expect creation-time code to work best on Windows and macOS.
Call File.SetCreationTimeUtc(path, dateTime). Pass a fixed DateTime when you want a predictable value for tests.

Next: GetLastAccessTime()

Read when a file was last opened or read, as a local DateTime.

GetLastAccessTime() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful