Jump to content
Sign in to follow this  
evilpacketmonkey

Creating a file/folder with localtime in the name

Recommended Posts

evilpacketmonkey

Goal: Create a file with the current (local) time as a part of the name. Problem is time and date outputs use illegal characters "/" and ":".

Example: Project_03_30_2009_17_52_10.txt

I cobbled some code together by using the "search" tool and the help file.

The question is, there is a better way to do this right?

#include <Date.au3>

Dim $tSystem, $tLocal, $TimeDate, $LocalArrayDate, $LocalArrayTime, $TimeDate, $LocalDateForFile, $Combined_DateTime_ForFile
Dim $LocalDateForFile, $LocalTimeForFile

_SystemTimeToLocalTimeArray()

Func _SystemTimeToLocalTimeArray()
  $tSystem = _Date_Time_GetSystemTime()
  $tLocal  = _Date_Time_SystemTimeToTzSpecificLocalTime(DllStructGetPtr($tSystem))
  $TimeDate = StringSplit(_Date_Time_SystemTimeToDateTimeStr($tLocal), ' ', 1)
  $LocalArrayDate = StringSplit($TimeDate[1], '/', 1)
  $LocalDateForFile = $LocalArrayDate[1] & "_" & $LocalArrayDate[2] & "_" & $LocalArrayDate[3]
  $LocalArrayTime = StringSplit($TimeDate[2], ':', 1)
  $LocalTimeForFile = $LocalArrayTime[1] & "_"& $LocalArrayTime[2] & "_" & $LocalArrayTime[3]
Global  $Combined_DateTime_ForFile = "_" & $LocalDateForFile & "_" & $LocalTimeForFile
EndFunc


MSGBOX(0, "Title", $Combined_DateTime_ForFile)

Share this post


Link to post
Share on other sites
Ascend4nt

All you need are macros..

@YEAR,@MON,@MDAY,@HOUR,@MIN,@SEC

Share this post


Link to post
Share on other sites
evilpacketmonkey

All you need are macros..

@YEAR,@MON,@MDAY,@HOUR,@MIN,@SEC

..ahh cool thanks. I knew it had to be something simple but I guess I was not seeing the forest through the tree's. My bad.

Thanks for your help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.