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

Convert Object of Type Date to a VB .Net Date

Status
Not open for further replies.

LaPiMg

Programmer
Oct 26, 2006
6
CA
Hi,

I'm using LAPI on Livelink 9.0.0 and having a few issues when handling dates. For example, I have this association (EnterpriseWorkspaceInfo) which I got from calling LL_AccessEnterpriseWS which has two dates. Using LL_AssocGetDate I get the value back, however my question is, how do I convert the value to the correct date?

I've tried to use the following VB .Net code and it does not seem to work all the time.

outField = DateAdd(DateInterval.Second, CType(outValue, Double), LLL_LiveLinkBaseDate)

where LLL_LiveLinkBaseDate = #12/31/1969 7:00:00 PM#

Thanks for your help
 
After reading the post, I realized that it is somewhat confusing. What I really mean is:

Const LLL_LiveLinkBaseDate As Date = #12/31/1969 7:00:00 PM#
Dim result As Int32
Dim outValue As Int32

result = LL_AssocGetDate(hAssociation, FieldName, outValue)
If result = LL_OK Then
' Here we convert the number of seconds in outValue
' to a VB .Net Date...
outField = DateAdd(DateInterval.Second, CType(outValue, Double), LLL_LiveLinkBaseDate)
End If

The question is, why doesn't this always works?
Appreciate your help.
Thanks
 
OK, I think I found the solution. Here is thre routine...

Friend Function GetDateFromValue(ByVal ValueDate As Int32, ByRef outField As Date) As Int32
Try
' Livelink dates are represented as the number of seconds since #12/31/1969 7:00:00 PM#
outField = DateAdd(DateInterval.Second, CType(ValueDate, Double), LLL_LiveLinkBaseDate)

' Now we have the date; there's a caveat though...
' Due to the daylight savings we need to figure out if
' the date did fall between the 1st Sunday of April at 2:00AM and the
' Last Sunday of October at 2:00AM and add 1 hour to count for the Daylight Savings
If outField.Year < 2007 Then
If outField.Month >= 4 And outField.Month <= 10 Then
' Let's find the First Sunday in April
Dim InitialDLSavingsDate As Date = CType(String.Concat(outField.Month.ToString, "/", "01", "/", outField.Year.ToString, " 2:00:00 AM"), Date)
InitialDLSavingsDate = InitialDLSavingsDate.AddDays((7 - InitialDLSavingsDate.DayOfWeek) Mod 7)

' Now, lets find the Last Sunday in October
Dim FinalDLSavingsDate As Date = CType(String.Concat(outField.Month.ToString, "/", "31", "/", outField.Year.ToString, " 2:00:00 AM"), Date)
FinalDLSavingsDate = FinalDLSavingsDate.AddDays(-1 * FinalDLSavingsDate.DayOfWeek)

' Does our date-time fall between these two dates?
If outField > InitialDLSavingsDate And outField < FinalDLSavingsDate Then
outField = outField.AddHours(1)
End If
End If
Else
' After 2007 Daylight Saving Time starts on the second Sunday in March and
' Daylight Saving Time ends on the first Sunday in November.
If outField.Month >= 3 And outField.Month <= 11 Then
Dim InitialDLSavingsDate As Date = CType(String.Concat(outField.Month.ToString, "/", "01", "/", outField.Year.ToString, " 2:00:00 AM"), Date)
InitialDLSavingsDate = InitialDLSavingsDate.AddDays(((7 - InitialDLSavingsDate.DayOfWeek) Mod 7) + 7)

' Now, lets find the First Sunday in November
Dim FinalDLSavingsDate As Date = CType(String.Concat(outField.Month.ToString, "/", "30", "/", outField.Year.ToString, " 2:00:00 AM"), Date)
FinalDLSavingsDate = FinalDLSavingsDate.AddDays((7 - FinalDLSavingsDate.DayOfWeek) Mod 7)

' Does our date-time fall between these two dates?
If outField > InitialDLSavingsDate And outField < FinalDLSavingsDate Then
outField = outField.AddHours(1)
End If
End If
End If
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top