Convert Julian Date to Gregorian Date in Powershell

So the other day I was presented with the issue of converting a Julian Date (YYYYDDD) to a Gregorian Date (MMDDYYYY).  After a few minutes in Powershell I realized that there was no built in way to do this.  A few minutes a Googling yielded a few long, bloated scripts.  I knew there had to be a better way, and there is!

Now we have a nice DateTime Object in our familiar Gregorian format. Useful for converting Julian dates in filenames or headers.

In a production setting you would definitely want to add some data validation to make sure the year is valid, the $JulianDay is a valid number between 1 and 365 (or 366 on a leap year), and so on.  Hope this helps, and happy scripting!

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *