Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default System time to GMT

I'm trying to figure out a way to convert the system time to GMT for use in
a userform. Any suggestions would be greatly appreciated.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default System time to GMT

Sub HIJ()
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colTimeZones = objWMIService.ExecQuery("Select * From Win32_TimeZone")
For Each objTimeZone In colTimeZones
intTimeZoneBias = objTimeZone.Bias
intDayLightBias = objTimeZone.DaylightBias
Debug.Print intTimeZoneBias, intDayLightBias
Next

gives me
-300 -60

divide these by 60 and you get the number of hours you need to add to
GMT/UTC. to get local time. In my Case, Eastern Standard Time, I need to
subtract 5 hours and an additional hour for Daylight Savings Time.

To convert from local to GMT/UTC, I would subtract these values (net result
is to add 6 hours).

--
Regards,
Tom Ogilvy




"Caleb Runnels" wrote:

I'm trying to figure out a way to convert the system time to GMT for use in
a userform. Any suggestions would be greatly appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default System time to GMT

Caleb,

If you know your offset from GMT, use either

=A1+TIME(H,0,0)
or
=A1-TIME(H,0,0)

where A1 is the time and H is the absolute value of the offset in hours from
local time to GMT. Use the addition version of the formula if your local
time is earlier than GMT (you are in western longitude) or use the
subtraction formula if GMT is earlier than your local time (you are in
eastern longitude).

For an in depth discussion of GMT and Excel, including example formulas and
VBA code, see http://www.cpearson.com/excel/LocalAndGMTTimes.htm . Also see
http://www.cpearson.com/excel/FileTimes.htm for a discussion of the times
used by FILETIME, SYSTEMTIME and local times and conversion between them.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)






"Caleb Runnels" wrote in message
...
I'm trying to figure out a way to convert the system time to GMT for use
in a userform. Any suggestions would be greatly appreciated.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy System Time Dave VB logic for excel Excel Discussion (Misc queries) 3 July 26th 07 03:31 PM
The 1904 Time System embirath[_3_] Excel Programming 11 August 19th 06 04:23 PM
system time and date kdp145[_5_] Excel Programming 0 March 21st 06 04:03 PM
what if system time is changed? JNW Excel Programming 2 October 27th 05 01:16 AM
Inserting the system time Dazza Excel Programming 2 May 18th 04 05:00 AM


All times are GMT +1. The time now is 03:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"