Date Format

C

Chris

Here at my shop we use peoplesoft and peoplesoft uses julian dates that look
like this: 107040. My question is if someone gave me a date in the format
of 02/09/07 on a form, how could I format it to look like 107040 so I could
scan the peoplesoft table? Any sugestions?
 
K

Klatuu

Create a standard module and paste this code into it. I call mine
modJulianDates, but you can name it according to your naming standards as
long as you don't name it the same as either of the function names. These
functions convert dates in either direction:

Option Compare Database
Option Explicit

Function JulDateToGregDate(ByVal varJulDate As Variant) As Date
Dim lngYearPart As Long
Dim lngDayPart As Long

varJulDate = Format(varJulDate, "00000")
lngYearPart = CLng(Left(varJulDate, 2))
If lngYearPart < 30 Then
lngYearPart = lngYearPart + 2000
Else
lngYearPart = lngYearPart + 1900
End If

lngDayPart = CLng(Right(varJulDate, 3))
JulDateToGregDate = DateSerial(lngYearPart, 1, lngDayPart)

End Function

Function GregDateToJulDate(dtmSomeDate As Date) As String
Dim lngDayPart As Long

lngDayPart = DateDiff("d", DateSerial(year(dtmSomeDate), 1, 0),
dtmSomeDate)
GregDateToJulDate = Format(dtmSomeDate, "yy") & Format(lngDayPart, "000")

End Function
 
Top