473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,322 developers and data experts.

Format system time to milliseconds in VBA

MMcCarthy
14,534 Expert Mod 8TB
I found I needed this recently when creating a file which had to be uploaded by ftp. The file extension was a timestamp of hhnnssms and the ms part was formatted to 4 digits. As the Now() function doesn't return milliseconds I used the following function to calculate it.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Type SYSTEMTIME
  5. wYear As Integer
  6. wMonth As Integer
  7. wDayOfWeek As Integer
  8. wDay As Integer
  9. wHour As Integer
  10. wMinute As Integer
  11. wSecond As Integer
  12. wMilliseconds As Integer
  13. End Type
  14.  
  15.  
  16. Private Declare Sub GetSystemTime Lib "kernel32" _
  17. (lpSystemTime As SYSTEMTIME)
  18.  
  19. Public Function TimeToMillisecond() As String
  20. Dim tSystem As SYSTEMTIME
  21. Dim sRet
  22.  
  23.     On Error Resume Next
  24.  
  25.     GetSystemTime tSystem
  26.  
  27.     sRet = Hour(Now) & Minute(Now) & Second(Now) & Format(tSystem.wMilliseconds, "0000")
  28.  
  29.     TimeToMillisecond = sRet
  30.  
  31. End Function
  32.  
As usual all advice, critique and enhancements welcome :)

Mary
Nov 13 '09 #1
2 22712
topher23
234 Expert 100+
I don't know how I missed this post... I was trying to do this very thing on Friday using SYSTEMTIME, got frustrated and just stuck with seconds. Thanks for providing a usable function, Mary!
Dec 8 '09 #2
MMcCarthy
14,534 Expert Mod 8TB
You're welcome !
Dec 9 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Valiz | last post by:
Hi, I am updating system time with IRIG time source which sends irregular pulses as shown below 11000011111100111111111111111111....(1-IRIG present and 0-IRIG not present) I need to update...
10
by: Partho Choudhury | last post by:
Hi all: I need to add a snippet which access the system time (upto atleast milliseconds) using ANSI std. C++. I cannot use MFC and Win32 APIs in my program for now for various reasons. Is there...
2
by: RAYYILDIZ | last post by:
Hi; I have some problem. In win32 platform, how I can get system time in location format. Location format is date and time where you are in. In some area's date format is mm.dd.yyyy, dd.mm.yyyy,...
8
by: marcus | last post by:
Is their a method in c++ or c that gives me the system time in milliseconds or higher resolution? I need it to be platform independent. Today I use timeGetTime which is windows specific. thanks
1
by: thomasamillergoogle | last post by:
Hello, My sql server 2000 database is on a shared server that I have absolutely no control over. When i run query select getdate() it is reporting the wrong time! I am pretty sure that the...
4
by: Mike Kearl | last post by:
I want to set the local Date Time of the xp systems in my organization using C# and a winform application. From what I have read this is not an easy task anymore. You have to obtain privlege...
8
jeffbroodwar
by: jeffbroodwar | last post by:
please help me get the system's time (with milliseconds) i need it to calculate the Soap request and response time in my SOAP project. i tried to use timer but the problem is, whenever i'm invoking a...
2
by: Mike | last post by:
I know, it is old question. Is there some new way to protect system time changes with C# 2.0? What is the best way based on your oppinion? Thanks, I appreciate your help. Mike
16
by: neelsfer | last post by:
I need to add milliseconds to this finishtime of race !!! = Format(Now(), "General Date") Start code for race also in milliseconds !!! = Format(Now(), "General Date") I will then subtract it...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.