Click here to Skip to main content
16,010,918 members

Comments by Shadar4263 (Top 2 by date)

Shadar4263 8-Apr-21 15:43pm View    
Maciej Los,
THANK YOU. I had slapped together the above "simplified code"to test and wasn't even paying attention to "formalities".
Your code wasn't the final solution but it did get me to thinking and I figured out that the double was returning in #.### format and I needed to get rid of the beginning zero to get it to go into the subroutine properly.

Final solution:
 'Original line of code I am trying to rework so it will function
        'Y = Year(ThisDate) + CDbl(ThisDate - DateSerial(Year(ThisDate), 1, 1)) / 365.25
        Dim JanuaryFirst As DateTime = New DateTime(ThisDate.Year, 1, 1)
        Dim tdiff As TimeSpan = ThisDate - JanuaryFirst
        Dim ddiff As Double = tdiff.TotalDays / 365.25 '188 / 365.25
        Dim resultDate As DateTime = JanuaryFirst.AddDays(ddiff)
        Dim strDDiff As String = ddiff.ToString
        Dim intIdx As Int16
        intIdx = strDDiff.IndexOf(".")
        strDDiff = strDDiff.Substring(intIdx, strDDiff.Length - 1)
        Y = ThisDate.Year.ToString & strDDiff
Shadar4263 8-Apr-21 12:40pm View    
I want to re-write that one line of code that will give me the same answer in VB .Net that I got in Excel VBA for a specific date.

Maybe if someone could explain why this line:

getdate = Thisdate - mydateserial

sets getdate to 7/6/1900 when the thisdate equals 7/8/2021 and mydateserial equals 1/1/2021 in Excel VBA.