Jump to content

Remove slashes from system date


Recommended Posts

I want to have the script open an Excel file and save it with the current system date and time in the name.

Trying to use StringSplit to get the date to write without the slashes, so 10/21/2009 becomes 10212009.

I used a modified version of a script in the forums here, and this is what I have:

#include <Date.au3>

$tTime = _Date_Time_GetSystemTime()

$split = StringSplit ($tTime, "/")

Run("C:\Program Files\Microsoft Office\Office11\Excel.exe")

WinWaitActive("Microsoft Excel - Book1")

Send("!f")

Send("a")

WinWaitActive("Save As")

Send("{Tab 6}")

Send("{Down}")

Send("{Enter}")

Send("RegistryData_"& $split)

Thanks for the help.

Link to comment
Share on other sites

I want to have the script open an Excel file and save it with the current system date and time in the name.

Trying to use StringSplit to get the date to write without the slashes, so 10/21/2009 becomes 10212009.

I used a modified version of a script in the forums here, and this is what I have:

#include <Date.au3>

$tTime = _Date_Time_GetSystemTime()

$split = StringSplit ($tTime, "/")

Run("C:\Program Files\Microsoft Office\Office11\Excel.exe")

WinWaitActive("Microsoft Excel - Book1")

Send("!f")

Send("a")

WinWaitActive("Save As")

Send("{Tab 6}")

Send("{Down}")

Send("{Enter}")

Send("RegistryData_"& $split)

Thanks for the help.

StringSplit() would format $Split like this: $Split[0] = 3, $Split[1] = 10, $Split[2] = 21, $Split[3] = 2009. Something you should try, or look at, is StringReplace() and replace the "/" with just a blank string ("")

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

... so 10/21/2009 becomes 10212009.

$split = StringSplit ($tTime, "/")

Send("RegistryData_"& $split)

$split becomes an array in the 2nd quoted line, not a string. So the last quoted line probably doesn't do what you expect.

If you really want to have what you specified in the 1st quoted line, use

$split = _ArrayToString($split, '') after the 2nd quoted line. (Requires #include <array.au3>)

edit: The '' in the last line are 2 single quotes, not a doublequote, specifying an empty string.

Iordicast's example does the same thing easier - this was just to clarify a possible missconception of StringSplit().

Edited by memoryoverflow

(The signature is placed on the back of this page to not disturb the flow of the thread.)

Link to comment
Share on other sites

$split becomes an array in the 2nd quoted line, not a string. So the last quoted line probably doesn't do what you expect.

If you really want to have what you specified in the 1st quoted line, use

$split = _ArrayToString($split, '') after the 2nd quoted line. (Requires #include <array.au3>)

edit: The '' in the last line are 2 single quotes, not a doublequote, specifying an empty string.

Iordicast's example does the same thing easier - this was just to clarify a possible missconception of StringSplit().

I tried lordicast's method, but the message box is blank.

#include <Date.au3>

$tTime = _Date_Time_GetSystemTime()

$string2 = Stringreplace($tTime,'/','')

MsgBox(0,'',$string2)

I will try working with memoryflow's suggestion now, but really thought the above would work.

Link to comment
Share on other sites

If you read the help file on it, and look at the example, it looks like this is required: _Date_Time_SystemTimeToDateStr(). I tried this

#include <Date.au3>

$tTime = _Date_Time_GetSystemTime()
MsgBox(0, "", _Date_Time_SystemTimeToDateStr($tTime))

and that returned the system date, and time. Then you just have to remove the time, and then try doing StringReplace() Take a look at the help file examples again

I put in a function that returned the time as well. I'm assuming you don't want that. It's just _Date_Time_SystemTimeToDateTimeStr() if you do. Formats mm/dd/yyyy hh:mm:ss

Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

why dont you just use this?

$Date = @MON&@MDAY&@YEAR

Added EX;

$Time = @HOUR&':'&@MIN&':'&@SEC
$Date = @MON&@MDAY&@YEAR
MsgBox(0,'',$Date &' '&$Time)

Thanks for all the help! Both suggestions worked. Out of principle I went with the StringReplace just so I knew I had correctly used something, although the method Lordicast suggested last is the simplest. The part that was causing the error previously was ommiting the _Date_Time_SystemTimeToDateTimeStr.

Here is what worked:

#include <Date.au3>

$tCur = _Date_Time_GetSystemTime()

$string = _Date_Time_SystemTimeToDateTimeStr($tCur)

$string2 = StringReplace($string,'/','')

$string3 = StringReplace($string2,':','')

MsgBox(0,'Time', $string3)

This allowed me to tack on the date and time onto a file so I could save updates in an archive rather than replacing.

Again thanks for your help and patience!

Link to comment
Share on other sites

I did not read all the responses so I apologize of this has already been stated but you can't have "/" or "\" and a couple other characters or symbols in names, at least not in windows.

Maybe there is a way around it but I am not sure how. I hope this was helpful if not I can remove it if I just made myself look stupid lol.

www.abox.orgAvery HowellVisit My AutoIt Websitehttp://www.abox.org
Link to comment
Share on other sites

And here's how to get system time into the string:

If you want to use _Date_Time_GetSystemTime() (it's more efficient without):

That function returns a SYSTEMTIME struct as defined in StructureConstants.au3

with the members 'Year', 'Month', 'Dow', 'Day', 'Hour', 'Minute', 'Second', 'MSeconds'

You can cast that in an array and then use the first tryied methods on it or use it directly:

#include <Date.au3>

Local $tSysTime = _Date_Time_GetSystemTime()
$sString = DllStructGetData($tSysTime, 2) & DllStructGetData($tSysTime, 4) & DllStructGetData($tSysTime, 1)

ConsoleWrite($sString & @CRLF)

(The signature is placed on the back of this page to not disturb the flow of the thread.)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...