Has anyone out there used the IMapTimeDisplay.TimeValue to get the current time from the timeslider control? I cannot figure out how to properly use it.

I am writing some code in VB .net that creates a bar graph (in a dockable window in ArcMap) from some of the attribute values in a polygon feature class. My feature class is time-enabled with an attribute called "Year" and the time slider is visible in ArcMap, but the data I send to the bar graph is not filtered by the current year selected on the slider. So, I need the current time to filter my data with.

I have the following which may not be correct, although it does not throw an error:

Dim pMxDoc As IMxDocument = TryCast(My.ArcMap.Application.Document, IMxDocument)
Dim pMap As IMap = pMxDoc.FocusMap
Dim pMapTimeDisplay As IMapTimeDisplay = pMap
Dim pTimeValue As ITimeValue = pMapTimeDisplay.TimeValue
Dim pTimeExtent As ITimeExtent = TryCast(pTimeValue, ITimeExtent)   'added

But, I can't figure out what to do from there. Can anyone help me please? I have searched the internet to the best of my ability.

Additional information I tried this, but it caused an error in ArcMap:

Dim currentYear As Integer = pTimeExtent.StartTime.Year

The error is "Unhandled exception has occurred..." and "System.NullReferenceException: Object reference not set to an instance of an object." Yet, I have used pTimeExtent.StartTime.Year successfully in other parts of my code to get the start time of the entire time range using pTimeExtent = pMapTimeDisplay.CurrentTimeExtent.

  • You need to recast your ITimeValue as ITimeInstant or ITimeExtent Jun 26, 2015 at 0:27
  • I tried recasting ITimeValue as ITimeExtent as so: Dim pTimeExtent As ITimeExtent = TryCast(pTimeValue, ITimeExtent) and then, I tried to get the pTimeExtent.StartTime.Year as well as the pTimeExtent.EndTime.Year, but both of these crashed ArcMap.
    – jencarta
    Jun 26, 2015 at 1:48

1 Answer 1


After much playing around with the various properties of the IMapTimeDisplay2 interface, I finally found something that worked. Perhaps this works because my dataset is time-enabled by an attribute called "Year" that has integer year values from 2010 to 2100 in 5 year increments, and I'm only interested in rendering one year at a time, so the "start time" and "end time" of the data displayed in the map are the same. Anyway, I recast my IMapTimeDisplay2.TimeValue to ITimeInstant as so:

Protected Overrides Sub OnClick()
    Dim pMxDoc As IMxDocument = My.ArcMap.Application.Document
    Dim pMap As IMap = pMxDoc.FocusMap
    Dim pTimeDisplay As IMapTimeDisplay2 = TryCast(pMap, IMapTimeDisplay2)
    Dim pTimeValue As ITimeValue = pTimeDisplay.TimeValue
    Dim pTimeInstant As ITimeInstant = TryCast(pTimeValue, ITimeInstant)
    If pTimeInstant IsNot Nothing Then
        Dim pCTime As ITime = pTimeInstant.Time
        Dim pCYear As Integer = pCTime.Year
        MsgBox(“time instant: " & pCYear)
    End If
End Sub

This is just a short bit of code to see if I could get just the current year that the time slider was on. It worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.