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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can "Julian Dates" be generated in Access97? 1

Status
Not open for further replies.

lbrink

IS-IT--Management
Jan 21, 2000
8
0
0
US
Tried looking in Date/Time - Format properties to no avail. Wondered if anyone out there has developed JULIAN DATE fields (i.e. YYYYJJJ). For example: February 1, 2000 would be converted to &quot;2000032&quot;. Thanks in advance for any help. (lbrink)<br>

 
Yes<br>
<br>
the first converts normal date to Julian <br>
<br>
<br>
Function NormalToJulian(Date1)<br>
Dim NormalDate As Date 'The serial date.<br>
Dim DateYear As String 'The year of the serial date.<br>
Dim JulianDay As String<br>
Dim JulianDate As String 'The converted Julian date value<br>
<br>
DateYear = Format(Date1, &quot;yyyy&quot;) 'Find the year number for NormalDate<br>
JulianDay = Format(Str(Date1 - DateValue(&quot;1/1/&quot; & Str(DateYear)) + 1), &quot;000&quot;)<br>
<br>
'Combine the year and day to get the value for JulianDate.<br>
JulianDate = DateYear & JulianDay<br>
<br>
NormalToJulian = JulianDate<br>
End Function<br>
<br>
-------------------------------------------------<br>
converts Julain to Normal 990312 to 12/03/1999<br>
<br>
Sub Convert_date()<br>
Dim dtmNewDate As Date<br>
Dim strJulianDate As String<br>
strJulianDate = wrkRqmtDate<br>
dtmNewDate = DateSerial(Left$(strJulianDate, 2), 1, 1)<br>
dtmNewDate = DateAdd(&quot;d&quot;, Val(Right$(strJulianDate, 3)) - 1, dtmNewDate)<br>
wrkRqmtDate = &quot;&quot;<br>
wrkRqmtDate = Format(dtmNewDate, &quot;mm/dd/yyyy&quot;)<br>
End Sub <br>
------------------
 
Interesting.

They are not 'complimentary'.

The first accepts an &quot;MS&quot; date and returns a seven Character string of the form &quot;yyyyddd&quot;.

The second (aparently?) accepts a SIX character string to (supposedly) return an MS date. Also, although the the 'description' shows the six character field, the actual code doesn't care what the length is (as long as it is at least three), as it only uses the first two and the last three.

The 2nd procedure also appears to be simply gouged out of some other process, as we also see variables which are not declared, and it is a &quot;SUB&quot; with no arguments.

So, just to tidy everything up a bit, I revised both to be the 'complimentary' pair I thought they were (or should be).

Code:
Function basMsDt2JulDt(DtIn As Date) As String

    'DougP 10/03/02  Tek-Tips thread181-5707

    Dim YrDt As String              'The year of the serial date.
    Dim JulDay As String

    YrDt = Format(DtIn, &quot;yyyy&quot;)     'Year from MS Date
    JulDay = Format(Str(DtIn - DateValue(&quot;1/1/&quot; & YrDt) + 1), &quot;000&quot;)

    basMsDt2JulDt = YrDt & JulDay

End Function
Public Function basJulDt2MsDt(strJulDt As String) As Date

    'DougP 10/03/02  Tek-Tips thread181-5707
    'converts &quot;Julain&quot; (YYYYDDD) to Ms Date (mm/dd/yy)
    '                  (1999337  to          12/03/99)

    Dim Idx As Integer
    Dim dtmNewDate As Date

    If (Len(strJulDt) <> 7) Then
        'See your favorite error handling HERE!
        Exit Function
    End If

    Idx = 1
    While Idx <= Len(strJulDt)
        MyChr = Mid(strJulDt, Idx, 1)
        If (Not IsNumeric(MyChr)) Then
            'See your (2nd) favorite error handling HERE!
            Exit Function
        End If
        Idx = Idx + 1
    Wend

    dtmNewDate = DateSerial(Left$(strJulDt, 4), 1, 1)
    dtmNewDate = DateAdd(&quot;d&quot;, Val(Right$(strJulDt, 3)) - 1, dtmNewDate)
    basJulDt2MsDt = Format(dtmNewDate, &quot;mm/dd/yyyy&quot;)

End Function
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
my julian date are 00204, 11483 etc...I forgot to say how do you convert a julian data such 00204 to a regular date in Access 2000. Thanks can I just copy the code in a new module. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top