2

Using this post "How to get UTC time with windows batch file" I've created a script that date and time stamps some directories for me when doing stuff...

REM *** Get time in UTC format, and set to variable called dame
for /f %%x in ('wmic path win32_utctime get /format:list ^| findstr "="') do set %%x
set dame=%Year%-%Month%-%Day%_%Hour%-%Minute%

set rundir=%dame%

mkdir %rundir%

There are other parts to my script, but it basically creates a directory structure as follows:

2018-3-22_14-10 (parent folder)
 |- Sun_2018-3-22_14-10 (sub folder)
 |- Sat_2018-3-22_14-10 (sub folder)
 |- Fri_2018-3-22_14-10 (sub folder)
 |- Thu_2018-3-22_14-10 (sub folder)

 etc.

I am in the UK and I have some testing to do this weekend when GMT changes to BST. I will be using Task Scheduler to run my script every 5 or 10 minutes.

My question is as follows; say the script created a directory like thus this weekend:

2018-3-25_00-55 (parent folder)
 |- Sun_2018-3-25_00-55 (sub folder)
 |- Sat_2018-3-25_00-55 (sub folder)
 |- Fri_2018-3-25_00-55 (sub folder)
 |- Thu_2018-3-25_00-55 (sub folder)

 etc.

That is, a run on Sunday 25th Mar at 00:55.

BST begins at 01:00 on Sunday 25th Mar. Will my folders be overwritten?

I do not think this will be the case for two reasons:

1) The clocks are going forward, so the next parent folder I would see would be "2018-3-25_02-00" worst case scenario and nothing over-written?

2) However, I'm using UTC, from wmic, as opposed to the local server time to get date/time. So the local time recorded would be 02:00 (UTC+1hr). As I am using UTC, the folder creation should stay at UTC+0hrs, and therefore the next parent folder I would see would be "2018-3-25_01-00"?

Following this logic, when BST returns to GMT again, I should not have to worry about over-writes as UTC should not change?

Ozymandias
  • 31
  • 7
  • 2
    I suppose that you create the folders on an NTFS formatted partition which stores file/folder dates in UTC which means no time jump on daylight saving time change for really stored dates, but returns the file/folder dates in local time resulting in a time jump for all folders and files on daylight saving time change. You can see that by changing time zone. For more details about date storing and display by various file systems and Windows versions see my answer on [Find out if file is older than 4 hours in batch file](https://stackoverflow.com/a/32670346/3074564). – Mofi Mar 23 '18 at 07:22
  • Thanks @Mofi, that was an interesting read. In essence, I think you've answered my question! As I am using UTC, which does not change throughout the year. The date/time folder creation should stay static, irrespective of how it's displayed according to local time. – Ozymandias Mar 23 '18 at 09:16
  • 1
    Yes, as you use the UTC time to define name of folder with date and time in name, daylight saving time adjustments do not matter. UTC time does not change by daylight saving time adjustments. The UTC time is increasing consecutively. UTC time of a computer changes only on synchronization to more precise time of a time server. NTP and PTP used usually for time synchronization use also UTC time. – Mofi Mar 23 '18 at 11:09

1 Answers1

0

So... the run over the weekend was successful, and folder structure was created as follows:

UTC vs Local time

"Date modified" jumped by 2 hours to reflect GMT+1hr (BST) and folder names reflect UTC time continuing unaffected.

Conclusion: If in a time zone that has daylight savings time adjustments; using UTC ensures date/time continuity.

Ozymandias
  • 31
  • 7