Timestamp with ms resolution

Hi to all,

i’m looking for a solution to create a timestamp with a millisecond resolution (windows)
Has anybody a idea how to do this?

Thanks
Jürgen

I have a function which I use to get a timestamp back as a string…

function gfstrGetDateAndTime ()

// Return date and time as…
// YYYY-MM-DD HH:MN:SS:mmm

#if TargetWin32
// -----------------------------------------------------

//- DLL entry point definition...
soft declare sub WinAPI_GetSystemTime  _
lib "Kernel32.dll" _
alias "GetSystemTime" ( _
ByVal memSysTime as ptr ) 

dim memSysTime as new MemoryBlock( 16 )
dim strOut as string

Call WinAPI_GetSystemTime( memSysTime )

//  Structure returned...
//      SYSTIME
//  Start byte  
//    0     wYear
//    2     wMonth           1 = January
//    4     wDayOfweek  0 = Sunday
//    6     wDay
//    8     wHour
//   10     wMinute
//   12     wSecond
//   14     wMillseconds
//   ---  
//   16

strOut = format( memSysTime.Int16Value(0), "0000" )
strOut = strOut + "-" + format ( memSysTime.Int16Value(2) , "00" )
strOut = strOut + " " + format ( memSysTime.Int16Value(6) , "00" )
strOut = strOut + ":" + format ( memSysTime.Int16Value(8) , "00" )
strOut = strOut + ":" + format ( memSysTime.Int16Value(10) , "00" )
strOut = strOut + ":" + format ( memSysTime.Int16Value(12) , "00" )
strOut = strOut + ":" + format ( memSysTime.Int16Value(14) , "000" )

RETURN ( strOut )

#else
// -----------------------------------------------------
// Target NOT windows…

dim datNow as date
dim strOut as string

datNow = new date

strOut = format( datNow.Year, "0000" )
strOut = strOut + "-" + format ( datNow.Month , "00" )
strOut = strOut + "-" + format ( datNow.Day , "00" )
strOut = strOut + " " + format ( datNow.Hour , "00" )
strOut = strOut + ":" + format ( datNow.Minute , "00" )
strOut = strOut + ":" + format ( datNow.Second , "00" )
strOut = strOut + ":000"


RETURN ( strOut )

#endif

Hi Chris,

thanks, thats exact the solution i was looking for.

Jürgen

Hi Chris,

I was also looking for this code, it works fine, but I need to do a timeshift as I live in CMT+1
It’s now one hour behind.
How can I add that to the code?

Best regards,

Olav

I think you just have to change it to call GetLocalTime instead of GetSystemTime

Thanks Chris, that works. Now I have my local pc time.
I changed it three times as below.

//- DLL entry point definition…
soft declare sub WinAPI_GetLocalTime _
lib “Kernel32.dll” _
alias “GetLocalTime” ( _
ByVal memSysTime as ptr )

dim memSysTime as new MemoryBlock( 16 )
dim strOut as string

Call WinAPI_[b]GetLocalTime[/b]( memSysTime )

OK: Glad it worked !

[quote=32617:@Chris Carter]function gfstrGetDateAndTime ()

// Return date and time as…
// YYYY-MM-DD HH:MN:SS:mmm

#if TargetWin32
// -----------------------------------------------------

//- DLL entry point definition…
soft declare sub WinAPI_GetSystemTime _
lib “Kernel32.dll” _
alias “GetSystemTime” ( _
ByVal memSysTime as ptr )

dim memSysTime as new MemoryBlock( 16 )
dim strOut as string

Call WinAPI_GetSystemTime( memSysTime )

// Structure returned…
// SYSTIME
// Start byte
// 0 wYear
// 2 wMonth 1 = January
// 4 wDayOfweek 0 = Sunday
// 6 wDay
// 8 wHour
// 10 wMinute
// 12 wSecond
// 14 wMillseconds
// —
// 16

strOut = format( memSysTime.Int16Value(0), “0000” )
strOut = strOut + “-” + format ( memSysTime.Int16Value(2) , “00” )
strOut = strOut + " " + format ( memSysTime.Int16Value(6) , “00” )
strOut = strOut + “:” + format ( memSysTime.Int16Value(8) , “00” )
strOut = strOut + “:” + format ( memSysTime.Int16Value(10) , “00” )
strOut = strOut + “:” + format ( memSysTime.Int16Value(12) , “00” )
strOut = strOut + “:” + format ( memSysTime.Int16Value(14) , “000” )

RETURN ( strOut )

#else
// -----------------------------------------------------
// Target NOT windows…

dim datNow as date
dim strOut as string

datNow = new date

strOut = format( datNow.Year, “0000” )
strOut = strOut + “-” + format ( datNow.Month , “00” )
strOut = strOut + “-” + format ( datNow.Day , “00” )
strOut = strOut + " " + format ( datNow.Hour , “00” )
strOut = strOut + “:” + format ( datNow.Minute , “00” )
strOut = strOut + “:” + format ( datNow.Second , “00” )
strOut = strOut + “:000”

RETURN ( strOut )

#endif[/quote]
But Only ads “:000” At the end of the date as Miliseconds, but It got no Real Miliseconds, So It doesn’t exist a real way to get Miliseconds?. Regards