Date To Julian Date Trouble 追蹤

0

My code was inspired from this example found on the web.

Function Date2Julian(vDate) 
 
    Date2Julian = CLng(Format(Year(vDate), "0000") _
                  + Format(DateDiff("d", CDate("01/01/" _
                  + Format(Year(vDate), "0000")), vDate) _
                  + 1, "000"))
    
End Function
 

This is my latest version in my many attempts to get this to work.

 

Data for label comes from XML

Shared/name = “IOLOT2”

Sample data from IOLOT2 = “EXP1602”

 

Originally use VBScript command “Format” got error,
“Unrecognized”, not FormatNumber.

 

Code that will not work

 

dim stryear

dim strMonth

dim vDate

dim strBatch

 

strBatch = IOLOT2

      

strBatch =  Mid(strBatch,4, LEN(strBatch) - 3)

 

strYear  = Left(strBatch ,2)

 

strMonth= Right(strBatch,2)

 

 vDate=strMonth & "/01/" & strYear

 

Value = CLng(FormatNumber(Year(vDate), "0000") &  FormatNumber(DateDiff("d", CDate("01/01/" & FormatNumber(Year(vDate), "0000")), vDate) & 1, "000"))


 

 

1 意見

0
Avatar
Legacy Poster
評論操作 永久連結

I figured out the problem.

 

I had used the script function "Format: many times, but it is unsupported by the Bartender script interpreter, and I was not familiar with "FormatNumber", so when I was getting an error from the function "CDate", I incorrectly thought that it was also unsupported . AS it turns out the FormatNumber function was adding a comma to the four digit year, and that was breaking the CDate function.

 

Here is the code that works.

 

dim stryear
dim strMonth
dim vDate
dim strBatch
strBatch = IOLOT2
strBatch =  Mid(strBatch,4, LEN(strBatch) - 3)

 

    strYear  = Left(strBatch ,2)
    strMonth= Right(strBatch,2)
    vDate=strMonth & "/01/" & strYear

 

Value = CLng(FormatNumber(Year(vDate), "0000") _
                  + FormatNumber(DateDiff("d", CDate("01/01/" _
                  + FormatNumber(Year(vDate), "0000",,,False)), vDate) _
                  + 1, "000"))

 


 

 

登入寫評論。