Formating dates with Powershell for different purposes

So Windows has lots of date formats to choose from. These are a few and functions to convert between them and Datetime.


The default timeformat that we are using in .NET and Powershell. This is probably the first date function you will learn to use. Or you can call on the .NET class.


Microsoft built time format that calculates number of 100 ns intervals since January 1, 1601. Yes this is a really large number. But even though the name suggest this is always for files it isn’t. Also in some file systems the resolution isn’t 100 ns just because the format has that as the smallest incrment.

I did a blog entry about a small discrepancy depending when creating dates using different methods and how they differed by 100ns. This was most easy to spot while looking at the time in a FileTime format.

MSDN page for FileTime structure

DMTF (Distributed Management Task Force) DateTime

As used by AD for some attributes and WMI. The format is almost easy to read.


Unix Epoch

This is the standard format used by *nix based systems. Number of seconds since January 1, 1970.

Also if you dont care about being compatible to older version you could use the [DateTimeOffset] class.

What about the other way then? That is really simpler.

An extra 100ns for free?

So I was reading up on the AD Module filters. I found a thing, Microsoft usually says keep it simple. I found an over complex way of initializing a date variable. So what did the documentation suggest:

Whoa.. Yes you can use .NET but if possible use Powershell cmdlets. Do we have any cmdlet we can use? Get-Date. Get-Date can be initialized with year, month and day.

That looks easier to read so it is better. But are they the same. And they arent. So what is the difference? Let’s convert it to the FileTime structure.

Here we see that we get a 100-nanosecond difference. Im not really sure why. But now we know that if you want the real 12am you cant use Get-Date. As it will add a 100ns extra. Bonus link to MSDN article for DateTime Structure.