I need a time stamp of the form:
%A_YYYY% %A_MM% %A_DD% %A_Hour% %A_Min% %A_Sec%
20181214123212
Problem is that when some of the variables (except for the year) are only 1 figure, for example minute 03 then the time stamp becomes only 13 chars: 2018121412312
So I add trailing zeros to the left of mm, dd, hh, mm and ss.
%A_YYYY% SubStr("0" . %A_MM%, -2) SubStr("0" . %A_DD%, -2) SubStr("0" . %A_Hour%, -2) SubStr("0" . %A_Min%, -2) SubStr("0" . %A_Sec%, -2)
It doesn't work as expected:
SubStr("0" . %A_Sec%, -2)
is still 1 figure when 0 < %A_Sec% <10
HOWEVER!!
SubStr("K" . %A_Sec%, -2) or SubStr("111" . %A_Sec%, -4)
works fine!
Seconds are now 'K3' or whatever the second is between 0 and 9, I can't add zeros to the left but I can add any other char/figure!
It seems like leading zeros are skipped since SubStr("100" . %A_Sec%, -4) works fine while SubStr("100" . %A_Sec%, -3) don't the leading zeros are gone.
Please help, this is REALLY testing my mental health!
Add zeros to the left
Re: Add zeros to the left
Hallo,
try:All three times always have 14 characters.
I recommend Time2.
try:
Code: Select all
Loop
{
Time1 = %A_YYYY%%A_MM%%A_DD%%A_Hour%%A_Min%%A_Sec%
FormatTime, Time2,, yyyyMMddHHmmss
Time3 := A_YYYY SubStr("0" . A_MM, -1) SubStr("0" . A_DD, -1) SubStr("0" . A_Hour, -1) SubStr("0" . A_Min, -1) SubStr("0" . A_Sec, -1)
ToolTip,% "Time1: " Time1 " " StrLen(Time1) " chars`nTime2: " Time2 " " StrLen(Time2) " chars`nTime3: " Time3 " " StrLen(Time3) " chars"
Sleep, 200
}
I recommend Time2.
Re: Add zeros to the left
Try A_Now:
I hope that helps.
edit: which is exactly option2, as recommended by Rohwedder in the post above.
Code: Select all
MsgBox, I need a time stamp of the form:`n...`n20181214123212`n`n%A_Now%
edit: which is exactly option2, as recommended by Rohwedder in the post above.
Re: Add zeros to the left
They aren't! A_MM, A_DD, A_Hour, A_Min, and A_Sec contain 2 digits.aircooled wrote:Problem is that when some of the variables (except for the year) are only 1 figure, for example minute 03 ...
Code: Select all
DateTime := Format("{:04}{:02}{:02}{:02}{:02}{:02}", Year, Month, Day, Hour, Min, Sec)
Re: Add zeros to the left
Thanks Rohwedder
it works
but my error was ridiculous
writing with spaces in between like this
Time1 = %A_YYYY% %A_MM% %A_DD% %A_Hour% %A_Min% %A_Sec%
make the zeros to the left vanish like for example in second #2 it gives not 02 but 2
writing like you did without spaces
Time1 = %A_YYYY%%A_MM%%A_DD%%A_Hour%%A_Min%%A_Sec%
works fine and msgbox gives
20181215164709
I don't understand why but it works fine without formatting
go figure
it works
but my error was ridiculous
writing with spaces in between like this
Time1 = %A_YYYY% %A_MM% %A_DD% %A_Hour% %A_Min% %A_Sec%
make the zeros to the left vanish like for example in second #2 it gives not 02 but 2
writing like you did without spaces
Time1 = %A_YYYY%%A_MM%%A_DD%%A_Hour%%A_Min%%A_Sec%
works fine and msgbox gives
20181215164709
I don't understand why but it works fine without formatting
go figure
Re: Add zeros to the left
Some code.
See also:
combining date variables is unreliable - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=36338
Code: Select all
FormatTime, vDate,, yyyy MM dd HH mm ss
MsgBox, % vDate
combining date variables is unreliable - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=36338
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Who is online
Users browsing this forum: RandomBoy and 181 guests