|
From: Jon on 25 Jul 2008 14:45 If I convert a date to a double e.g. CDbl(Now), I get something like 39654.4780208333 I understand this double value contains the milliseconds as well. Now, if I convert this double back to a date, i.e. CDate(39654.4780208333), I get '7/25/2008 11:28:21 AM' So, my question is how do I get the milliseconds from the double value? Thanks Jon
From: Karl E. Peterson on 25 Jul 2008 14:54 Jon wrote: > If I convert a date to a double > > e.g. CDbl(Now), I get something like 39654.4780208333 > > I understand this double value contains the milliseconds as well. How did you come to that understanding? I ask, because a few simple tests suggest that's not true. ?cdbl(now-datevalue(now)) * 86400 If you want the passage of milliseconds, I'd suggest you use GetTickCount or timeGetTime. You'll need to "calibrate" it to the systemtime, of course. -- ..NET: It's About Trust! http://vfred.mvps.org
From: Tony Proctor on 25 Jul 2008 15:28 Following from what Karl said, a Date value holds the fraction of a day (i.e. the h, m, and s parts) in the fractional part of that Double value. So, yes, it probably is possible for a Date variable to hold millisecond values. However, the Now() function only returns times to 1 second resolution. Also, I'm not sure whether run-time support functions like DateAdd and DateDiff will acknowledge and retain those millisecond contributions - I've never tried it. Here's one easy way to get milliseconds for display purposes, e.g. when logging progress messages:- Public Function sFormatNowMS(Optional sFmt As String = "ddddd hh:nn:ss.fff") As String ' Formats 'now' as a text string down to millisecond resolution. The format string will accept ' ".fff" for milliseconds, the same as VB.Net. The default format string will generate a full ' date/time incorporating milliseconds. Dim dNow As Date, lMS As Long ' Get normal date/time, to seconds resolution, and milliseconds from midnight. NB: must be in synch Do While dNow <> Now() dNow = Now(): lMS = CLng(Timer() * 1000) Loop sFormatNowMS = Format$(dNow, sFmt) sFormatNowMS = Replace$(sFormatNowMS, ".fff", Format$(lMS Mod 1000, "\.000")) End Function Tony Proctor "Jon" <Jon(a)discussions.microsoft.com> wrote in message news:C1B540F4-80C7-4789-91A5-65B77B58CC4A(a)microsoft.com... > If I convert a date to a double > > e.g. CDbl(Now), I get something like 39654.4780208333 > > I understand this double value contains the milliseconds as well. > > Now, if I convert this double back to a date, > > i.e. CDate(39654.4780208333), I get '7/25/2008 11:28:21 AM' > > So, my question is how do I get the milliseconds from the double value? > > Thanks > Jon >
|
Pages: 1 Prev: Knowing the caller form in VB6 Next: Determine When a User Logged In |