Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert.ToDateTime Method (Int64)
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00810877
Message ID:
00812852
Views:
13
>Thanks for your reply Joe,
>
>Perhaps you can provide an example when you return from Philly. I looked at the help, and played with some code, but I don't see how I can make this work to convert a signed 64-bit integer to a datetime format.
>
>If you can provide any additional information I will be very grateful!
>
>Thanks,
>- Kile
>
>>Look at TimeOfDay.xxx
>>
>>Gotta run, I am of to Philly. I will not be able to chime in before then.
>>
>>HTH,
>>
>>
>>>Scanning the .NET help files, help for the Convert.ToDateTime Method (Int64) returns the following information:
>>>
>>>"This conversion is not supported..."
>>>
>>>What's up with this?
>>>
>>>Specifically, I am writing a VB.NET routine that is querying Active Directory. First of all, I can't understand why the following AD fields are of data type Long:
>>>    badpasswordTime
>>>    pwdlastset
>>>    usncreated
>>>    accountexpires
>>>    lastlogoff
>>>    usnchanged
>>>
>>>...while the following fields are of data type Date:
>>>    whencreated
>>>    whenchanged
>>>
>>>They should all be date-time values shouldn't they?
>>>
>>>It wouldn't be a problem if the routine mentioned in the subject of this email were available, but it's not. How would one go about converting one of these 64-bit signed integer values to its equivalent DateTime format value (using VB.NET)?
>>>
>>>Thanks in advance!

Hi Kile, I spent some time on this last night. Create a form with 3 list boxes [lstTime,lstDiff,lstDate] and a timer [tmrSeconds]. Set the timer interval to (1 sec)1000. I lined the list boxes up so I could get a good visual representation. I have included the code below. No imports or impliments are needed. I included the progression of my experimentation for you to see. It looks like d.FromFileTimeUtc(lngticks).AddYears(-1600) is the answer. I am sure someone here can solve the extra 1600 years issue. I tried with both date and datetime
anyway here is the code. Work with it a little and let me know how it goes.
    Private Sub tmrSeconds_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrSeconds.Tick
        Dim dt As DateTime = DateTime.Now
        Dim d As Date = Now

        If lstTime.Items.Count < 25 Then
            Dim lngticks As Long = dt.Ticks
            ' lstDate.Items.Add(dt.TimeOfDay.FromTicks(lngticks)) ' Poor formating
            'lstDate.Items.Add(dt.FromFileTimeUtc(lngticks)) ' Why the year is 3603 I dont know.  
            'lstDate.Items.Add(d.FromFileTimeUtc(lngticks))   ' Why the year is 3603 here too, I dont know.  
            lstDate.Items.Add(d.FromFileTimeUtc(lngticks).AddYears(-1600)) ' this is definately a hack :(
            lstTime.Items.Add(lngticks.ToString)
            If lstTime.Items.Count > 1 Then
                lstDiff.Items.Add(lstTime.Items.Item(lstTime.Items.Count - 2) - lstTime.Items.Item(lstTime.Items.Count - 1))
            Else
                lstDiff.Items.Add("Start")
            End If
        End If
    End Sub


HTH,
~Joe Johnston USA

"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams

Previous
Next
Reply
Map
View

Click here to load this message in the networking platform