FileDateTime to UTC

breynolds0431

Active Member
Joined
Feb 15, 2013
Messages
303
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello. I have a main file that updates data from an external file on Workbook_Open and Workbook_BeforeSave. When it updates, it writes the date/time to a named range in the sheet of the main file (not the external file). I then use that update's date and time to evaluate if an update should be made when the main file is opened/closed using the FileDateTime() of the external file. That is, if the date/time on the sheet in the main file is less than the date/time of the FileDateTime(ExternalFile), then the update should run.

The problem comes to play when someone from another time zone opens the main file. I know how to convert local time to UTC, which could be added during the update to the main file's sheet. But, I think I would also need a way to convert the FileDateTime(ExternalFile) to UTC as well. Otherwise, there would likely be a couple hours not being considered. Anyone know of a way to convert FileDateTime() to UTC?

VBA Code:
Private Sub Workbook_Open()

'Will only run Hub Data update if the Hub modify date/time changed
Dim specs As Range: Set specs = ThisWorkbook.Sheets("UpdateSpecs").range("HubDtTm")
Dim FilePath As String: FilePath = "T:\FSD\AR\Hub Log\"
Dim MyFile As Variant: MyFile = Dir$(FilePath & "*.xlsb")

'specs is already UTC converted
'>>this is where (I'm thinking), FileDateTime would need to be converted to UTC
If specs < FileDateTime(FilePath & MyFile) Then
     Call UpdateHubData
End If

With Application
    .ScreenUpdating = True
    .EnableEvents = True
End With
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try the code solution at:

and call the UTCtoLocal function from your code like this:
VBA Code:
If specs < UTCtoLocal(FileDateTime(FilePath & MyFile)) Then
I would also change the specs variable to an Excel date, like this:
VBA Code:
Dim specs As Date: Set specs = ThisWorkbook.Sheets("UpdateSpecs").range("HubDtTm").Value
 
Upvote 0
Solution
Try the code solution at:

and call the UTCtoLocal function from your code like this:
VBA Code:
If specs < UTCtoLocal(FileDateTime(FilePath & MyFile)) Then
I would also change the specs variable to an Excel date, like this:
VBA Code:
Dim specs As Date: Set specs = ThisWorkbook.Sheets("UpdateSpecs").range("HubDtTm").Value
Thanks! I used the LocaltoUTC so that both dates were being updated to UTC. Appreciate the recommendation on the Date variable for specs as well.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top