Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Julian date 1

Status
Not open for further replies.

NotSQL

Technical User
Joined
May 17, 2005
Messages
205
Location
GB
Can anyone give me a bit of code that allows me to convert todays date into a julian date format?

Regards
 
Something like this?

Code:
dim d
dim i
d = date
i = (year(d) - 1900) * 1000 + date - cdate("31/12/" & year(d) - 1)
msgbox(i)

Hope this helps.

[vampire][bat]
 
That works fine Earth and Fire, however, if you think your good how would i convert the first day of the month into a julian date format?
 
Try:

Code:
dim d
dim i
d = cdate("1/" & month(date) & "/" & year(date))
i = (year(d) - 1900) * 1000 + d - cdate("31/12/" & year(d) - 1)
msgbox(i)

Hope this helps


[vampire][bat]
 
This example uses documented functions provided for the purpose and avoids (1.) unnecessary string concatentation and (2.) localization timebombs in the string representations of dates:
Code:
Option Explicit

Dim dtToday
Dim intJToday
Dim dt1stOfMonth
Dim intJ1stOfMonth

Function DateToJulian(ByVal DateVal)
  'Convert native Date format to an
  'Integer of the form YYYYDDD.
  DateToJulian = Year(DateVal) * 1000 _
               + DatePart("y", DateVal)
End Function

dtToday = Date()

intJToday = DateToJulian(dtToday)
MsgBox "Today: " & CStr(intJToday)

dt1stOfMonth = DateSerial(Year(dtToday), Month(dtToday), 1)

intJ1stOfMonth = DateToJulian(dt1stOfMonth)
MsgBox "First of this month: " & CStr(intJ1stOfMonth)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top