Converting MS's "Integer8" Date/Time

182 views
Skip to first unread message

jxt666

unread,
Sep 8, 2014, 7:28:18 PM9/8/14
to intersystems...@googlegroups.com
Cache 2012.1/OpenVMS

I'm writing a routine using LDAP to access MS Active Directory to extract some fields.  Some of the date/time fields are in "Integer8" format of a 64-bit value representing 100-nanoseconds "ticks" since 1/1/1601.  I need to convert these to a displayable date/time format.  I've asked Intersystems, but they have no conversion routines.  The conversion to the $H format seems like a lot of work so I wanted to ask if anyone has already done this.  Note that this format is used by MS for other date/time fields besides AD, specifically in the Windows directory.  Thanks

Lyle Marti

unread,
Sep 8, 2014, 9:22:32 PM9/8/14
to intersystems...@googlegroups.com
Wow that sounds like fun to write that conversion routine.  I will play around and see what I can come up with. First to divide the integer8 by one billion....

On Mon, Sep 8, 2014 at 5:28 PM, jxt666 <jxt...@gmail.com> wrote:
Cache 2012.1/OpenVMS

I'm writing a routine using LDAP to access MS Active Directory to extract some fields.  Some of the date/time fields are in "Integer8" format of a 64-bit value representing 100-nanoseconds "ticks" since 1/1/1601.  I need to convert these to a displayable date/time format.  I've asked Intersystems, but they have no conversion routines.  The conversion to the $H format seems like a lot of work so I wanted to ask if anyone has already done this.  Note that this format is used by MS for other date/time fields besides AD, specifically in the Windows directory.  Thanks

--
--
Caché, Ensemble, DeepSee

---
You received this message because you are subscribed to the Google Groups "Caché, Ensemble, DeepSee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to intersystems-publi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bill Farrell

unread,
Sep 8, 2014, 9:54:33 PM9/8/14
to intersystems...@googlegroups.com
Here's a couple of methods I wrote for juggling CacheMV and *nix epoch dates. These might give you a running start. You can plonk them into an existing library class. Just set [Language = MVBasic] in the function declaration line or I can translate them to COS.

Bill


/// Convert between Pick and Unix Epoch dates</p>
/// <p>Options can be in any order and consist of the following flags:</p>
///
///    <li>D - Return only the date part</li>
///    <li>T - Return only the time part</li>
///    <li>I - Return the requested value part in internal format</li>
/// </ul>
/// <P>If no options are specified, then an external date-and-time string
/// is returned.</P>
///
/// <p>If "I" is specified, then either "D" or "T" must be specified.</p>
ClassMethod UDate(UnixDate As %Integer = 0, OptionFlags As %String = "") As %String  [Language = mvbasic]
{
   
    If Unassigned( %MVBDebugging ) Then %MVBDebugging = @false
    IF Unassigned( %MVBExtendedDebugging ) Then %MVBExtendedDebugging = @false

    If $Get(%MVBCommon) = "" Then %MVBCommon = "MVBooster.Common"->%New()
   
   IF Abs( UnixDate ) = 0 THEN
      RETURN OCONV( @date, "D4/" )
   END

   Time = REM( UnixDate, 86400 )
   Days = INT( ( UnixDate - Time ) / 86400 ) + 732

   BEGIN CASE

      CASE OptionFlags = %MVBCommon->nil
         Results = OCONV( Days, "D4/" ) : " " : OCONV( Time, "MTS" )

      CASE ( INDEX( OptionFlags, "D", 1 ) > 0 )

         IF INDEX( OptionFlags, "I", 1 ) > 0 THEN
            Results = Days
         END ELSE
            Results = OCONV( Days, "D4/" )
         END

      CASE ( INDEX( OptionFlags, "T", 1 ) > 0 )

         IF INDEX( OptionFlags, "I", 1 ) > 0 THEN
            Results = Time
         END ELSE
            Results = OCONV( Time, "MTS" )
         END

   END CASE

   RETURN Results
}

/// Return the unix epoch equivalent of a pick date and time.  If the time isn't
/// supplied, midnight (the start of the day) is assumed
ClassMethod UDateFromPDate(PickDate As %Integer, PickTime As %Integer) As %BigInt [Language = mvbasic]
{
    If $Get( %MVBCommon ) = "" Then %MVBCommon = "MVBooster.Common"->%New()
   
    If Not( PickDate Matches "1N0N" ) Then InternalPickDate = IConv( PickDate, 'D' )
    If Not( PickTime Matches "1N0N" ) Then InternalPickTime = IConv( PickTime, "MTS" )
   
    If Status() <> %MVBCommon->successful Then
        "MVBooster.Library"->SetCondition( Status(), "Invalid date for conversion." )
        Return 0
    End
   
    JDate = ( PickDate - 732 ) * 86400
   
    Return JDate + PickTime
Reply all
Reply to author
Forward
0 new messages