-2

I have a UTC DateTime value: 12:00 midnight, January 1, 1601 A.D. (C.E.), UTC

How would I hardcode this UTC DateTime value in C#

if (job.DateTimeValue == <UTC value>)
user989988
  • 3,006
  • 7
  • 44
  • 91

1 Answers1

1

The DateTime type has a constructor that allows you to set:

  • Year
  • Month
  • Day
  • Hour
  • Minute
  • Second
  • Millisecond
  • DateTimeKind (UTC, Local, Unspecified)

var jobMinDateValue = new DateTime(1601, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

if (job.DateTimeValue == jobMinDateValue)
{
    // ...
}

12:00 midnight, January 1, 1601 A.D. (C.E.), UTC happens to be a special date & time on Windows... Windows represents FileTime as the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC).

That means that in FileTime terms the value 0 means 12:00 midnight, January 1, 1601 A.D. (C.E.), UTC

That gives you another alternative to get the same value you're looking for:

var jobMinDateValue = DateTime.FromFileTimeUtc(0);

if (job.DateTimeValue == jobMinDateValue)
{
    // ...
}
C. Augusto Proiete
  • 24,684
  • 2
  • 63
  • 91