Skip to content

Instantly share code, notes, and snippets.

@JamesHovious
Last active December 6, 2021 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesHovious/7652469 to your computer and use it in GitHub Desktop.
Save JamesHovious/7652469 to your computer and use it in GitHub Desktop.
PowerShell function to get today's Julian Date
#Calculate today's julian date
$Year = get-date -format yy
$JulianYear = $Year.Substring(1)
$DayOfYear = (Get-Date).DayofYear
$JulianDate = $JulianYear + "{0:D3}" -f $DayOfYear
Write-Host $JulianDate
@dmurray2413
Copy link

Nice... but wrong. While commonly "called" Julian date, what you represented is NOT a Julian date. Google it.
Julian dates (abbreviated JD) are simply a continuous count of days and fractions since noon Universal Time on January 1, 4713 BC (on the Julian calendar). Almost 2.5 million days have transpired since this date. Julian dates are widely used as time variables within astronomical software. )

@atkinsroy
Copy link

Agreed. What you have there is commonly referred to as the Julian Day - days- one-based numbered from 1st Jan. The Julian Calendar is predecessor to Gregorian calendar without the some of leap year adjustments - so as a result they're drifting apart over time.
Also, its much easier to calculate the Julian day using this:

Get-Date -UFormat %j

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment