Julian to Gregorian VBA

OO7Goofy

New Member
Joined
Jul 10, 2018
Messages
13
I am attempting to solve a problem of finding the difference between two times. The times are downloaded and displayed in a single cell i.e. "8363/0031". The first 4 numbers is the Julian Date and the last 4 are hhmm in 24 hour format. I need to subtract one cell from another and display the difference as HH:MM. For example, if a1 = 8363/0031 and a2 = 8362/2018, I need a1-a2 to print 04:13 in b1.

Thank you in advance for the help.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try:

=IF(RIGHT(A2,4)>RIGHT(A1,4),1,0)+TIME(LEFT(RIGHT(A1,4),2),RIGHT(A1,2),0)-TIME(LEFT(RIGHT(A2,4),2),RIGHT(A2,2),0)
 
Upvote 0
a​
b​
1​
8363/0031
2​
8362/2018
3​
4:13​
a3: =abs(left(a1,4) + text(right(a1, 4), "00\:00") - left(a2, 4) - text(right(a2, 4), "00\:00"))
 
Upvote 0
Thank you for the quick reply. I'm attempting to do this in VBA as the cells I'm comparing are not always in order.
 
Upvote 0
Code:
Sub demo()
  Range("A1").Value = "8363/0031"
  Range("A2").Value = "8362/2018"
  MsgBox Format(DeltaT([a1], [a2]), "h:mm")
End Sub

Function DeltaT(s1 As String, s2 As String) As Date
  ' returns the absolute value of the difference in time between s1 and s2,
  ' which are formatted as d[d..]/hhmm, where dddd is a Julian day number.
  Dim t1 As Date
  Dim t2 As Date
  
  t1 = Left(s1, InStr(s1, "/") - 1) + CDate(Format(Right(s1, 4), "00\:00"))
  t2 = Left(s2, InStr(s2, "/") - 1) + CDate(Format(Right(s2, 4), "00\:00"))
  DeltaT = Abs(t1 - t2)
End Function
 
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,724
Members
449,465
Latest member
TAKLAM

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