From time-to-time I have noticed, on the various news groups, a request to convert a Julian date to a date. Julian dates are represented in the format yyddd, where yy is the year and ddd is the day of the year. For example: 01001 is January 1, 2001, 01365 is December 31, 2001. I wrote a class module that will convert a Julian date to its equivalent VB date and back.
I wrote a simple VB 6 program to demonstrate the use of the class module. A screen shot of the demo:
Enter a Julian date then click 'Julian to Date' to convert the Julian date to a VB date. Or select a date from the calendar then click 'Date to Julian' to convert it to Julian format.
I encapsulated the code to convert a Julian date in a class module called 'clsJulianToDate'. An object view of the class.
Methods and Properties
DateToJulian Convert a VB date to Julian format JulianToDate Convert a Julian date to VB date format. DaysInTheYear Returns the number of days in the year specified by a VB Date LastDayOfTheYear Returns the last day of the year specified by a VB Date
To use the code define a 'clsJulianToDate' object. Sample code extracted from the demo program:
Dim obj As New clsJulianToDate 'Julian converter class
Select Case Index
Case 0 'Julian to Date
Me.DTPicker1.Value = obj.JulianToDate(CLng(Me.Text1.Text))
Case 1 'Date to Julian
Me.Text1.Text = obj.DateToJulian(Me.DTPicker1.Value)
Include In Your Application
clsJulianToDate.cls Support date conversion.
The Demo Program Uses MSComCt2.ocx
The demo program uses the Microsoft Windows Common Controls 2, Calendar Control. You will need a registered version to use the demo. You could substitute another calendar control. The calendar control is not needed by the class module.
The Demo Program Uses modConnectToWebSite
The demo program uses modConnectToWebSite.bas to display this page. For details on the use of that module click here.
Comment from Michael Cole - April 4, 2002
On the "Julian to VB Date and Back - April 2001", I believe that you may have your terminology incorrect. [From http://aa.usno.navy.mil/data/docs/JulianDate.html], "Julian dates (abbreviated JD) are simply a continuous count of days and fractions since noon Universal Time on January 1, 4713 BCE (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." Note that there does seem to be some confusion about this, but given my interest in astronomy, this tends to erk me. What you have shown, IMO, should more properly be called simply, "Day of Year."
Comment from Arthur Schwieger - October 9, 2003
I was in need of a Julian to Gregorian conversion routine in VB and I found your site. I like the code and will use part of it! Thank you.
Arthur Schwieger, McKesson Medication Management
Download VB 6 Source Code
Click here to download the VB 6 source code [6k]
Previous Tip Tip Index Next Tip