VBA for Julian Date

FFischer

Board Regular
Joined
Oct 10, 2013
Messages
59
I needed VBA code for turning today into a Julian Date. I finally got it to work and thought I would share...
Code:
Sub Julian()

Dim AWB As WorksheetFunction, JulianDate As String
Set AWB = Application.WorksheetFunction

JulianDate = AWB.Text(AWB.Days(Date, 1) - AWB.Days(DateSerial(Year(Date), 1, 0), 1), "000")

MsgBox JulianDate

End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
You shouldn't need to make any worksheet function calls, and there is no worksheet function called Days:

Code:
Sub Julian()
Dim dt As Date
dt = Date
MsgBox Year(dt) & Format(dt - DateSerial(Year(dt), 1, 1) + 1, "000")
End Sub

Drop the Year(dt) &
if you don't want the year
 
Upvote 0
You shouldn't need to make any worksheet function calls, and there is no worksheet function called Days:

Code:
Sub Julian()
Dim dt As Date
dt = Date
MsgBox Year(dt) & Format(dt - DateSerial(Year(dt), 1, 1) + 1, "000")
End Sub

Drop the Year(dt) &
if you don't want the year

Alternately...

Code:
Sub Julian()
  MsgBox Year(Date) & Format(DatePart("y", Date), "000")
End Sub
 
Upvote 0
There is in Excel 2013

Then they must have added it in XL2013 (I don't have that version, so I cannot check it), but it did not exist in XL2010 or earlier. So... if you plan to use it, remember that no one using an earlier version of Excel will be able to use your workbook.
 
Upvote 0
I needed VBA code for turning today into a Julian Date. I finally got it to work and thought I would share...
Code:
Sub Julian()

Dim AWB As WorksheetFunction, JulianDate As String
Set AWB = Application.WorksheetFunction

JulianDate = AWB.Text(AWB.Days(Date, 1) - AWB.Days(DateSerial(Year(Date), 1, 0), 1), "000")

MsgBox JulianDate

End Sub
I just want to verify this works for perpetual and leap year right
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top