Date Format

  • Thread starter Thread starter Chris
  • Start date Start date
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?
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top