Simpel formattime
Simpel formattime
Hi guys
I have a date string thats YYYYMMDD-XXXX
If i put it through
FormatTime, time , [YYMMDD XXXX] Will it come out as YYMMDD XXXX?
Or im i missing somthing?
I have a date string thats YYYYMMDD-XXXX
If i put it through
FormatTime, time , [YYMMDD XXXX] Will it come out as YYMMDD XXXX?
Or im i missing somthing?
Re: Simpel formattime
Hallo,
try this:and that:
try this:
Code: Select all
FormatTime, time,, yyyyMMdd-HHmm
MsgBox, % "Time now:`n" time
FormatTime, time, yyyyMMdd-HHmm, yyyyMMdd HHmm
MsgBox, % "Time reformatted:`n" time
Code: Select all
FormatTime, time,, yyyyMMdd-HHmm
MsgBox, % "Time now:`n" time
time := StrReplace(time,"-"," ")
MsgBox, % "Time reformatted:`n" time
Re: Simpel formattime
Hi
Thx for your code. Two questions. I'm gonnea use both of them? And they seem to only give todays date? I would like the to give a date thats in the format YYYYMMDD-XXXX thats on the clipboard and that comes out as the script that you posted.
Thx for your code. Two questions. I'm gonnea use both of them? And they seem to only give todays date? I would like the to give a date thats in the format YYYYMMDD-XXXX thats on the clipboard and that comes out as the script that you posted.
Re: Simpel formattime
- What is XXXX? Is it HHmm? That information is crucial.
- FormatTime can only handle blank (for the time now) or a number of the form yyyyMMddHHmmss, or a partial string e.g. of the form yyyyMMdd or yyyyMMddHHmm.
- So, some possible input values: 20060504030201, 200605040302, 2006050403, 20060504, 200605, 2006, (blank string, for the time now).
- Here's some code:
- [EDIT:] I slightly misread your first post, here's the exact format you specified:
- [EDIT:] Here are some basic RegEx checks to check the datestamp:
- FormatTime can only handle blank (for the time now) or a number of the form yyyyMMddHHmmss, or a partial string e.g. of the form yyyyMMdd or yyyyMMddHHmm.
- So, some possible input values: 20060504030201, 200605040302, 2006050403, 20060504, 200605, 2006, (blank string, for the time now).
- Here's some code:
Code: Select all
q:: ;convert dates - 'yyyyMMdd-HHmm' to 'yyyyMMdd HHmm'
;conversion approach 1:
vDate := "20060504-0302"
vDate := StrReplace(vDate, "-", " ")
MsgBox, % vDate
;conversion approach 2:
vDate := "20060504-0302"
vDate := StrReplace(vDate, "-")
FormatTime, vDate, % vDate, yyyyMMdd HHmm
MsgBox, % vDate
return
Code: Select all
q:: ;convert dates - 'yyyyMMdd-HHmm' to 'yyMMdd HHmm'
;conversion approach 1:
vDate := "20060504-0302"
vDate := SubStr(StrReplace(vDate, "-", " "), 3)
MsgBox, % vDate
;conversion approach 2:
vDate := "20060504-0302"
vDate := StrReplace(vDate, "-")
FormatTime, vDate, % vDate, yyMMdd HHmm
MsgBox, % vDate
return
Code: Select all
q:: ;RegEx - check datestamp
vDate := "20060504-0302"
MsgBox, % RegExMatch(vDate, "^\d{8}-\d{4}$") ;yyyyMMdd-HHmm
vDate := "060504 0302"
MsgBox, % RegExMatch(vDate, "^\d{6} \d{4}$") ;yyMMdd HHmm
return
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
Re: Simpel formattime
XXXX is not HHmm , its number going from 0101 to 9999.
Hmm. I realy just want to get the "-" and "19" to go away so the number presents itself as YYMMDD XXXX. Rohwedeers code did that to some degree
Hmm. I realy just want to get the "-" and "19" to go away so the number presents itself as YYMMDD XXXX. Rohwedeers code did that to some degree
Re: Simpel formattime
Hallo,
@jeeswg:
FormatTime can only handle … a number of the form yyyyMMddHHmmss … ??
try:
@jeeswg:
FormatTime can only handle … a number of the form yyyyMMddHHmmss … ??
try:
Code: Select all
FormatTime, time,, MM*yyyy:dd+mmHH
MsgBox, % "Time coded`n" time
FormatTime, time, MM*yyyy:dd+mmHH, yyyyMMdd HHmm
MsgBox, % "Time reformatted:" time
Re: Simpel formattime
Yo Rohwedder
does exactly what I want it to do (gone use it on clipboard but, thats not important right now.)
The only problem is that ist only formating todays date and not the date that i copied on to the cliboard.
Code: Select all
FormatTime, time,, yyyyMMdd-HHmm
MsgBox, % "Time now:`n" time
FormatTime, time, yyyyMMdd-HHmm, yyMMdd HHmm
MsgBox, % "Time reformatted:`n" time
The only problem is that ist only formating todays date and not the date that i copied on to the cliboard.
Re: Simpel formattime
- That sounds like a simple string manipulation, one of my examples above achieved that, here it is again. You replace hyphens with spaces, and crop the first 2 characters via SubStr.
- @Rohwedder: I'm not sure what you mean, can you give a concrete example? Cheers.
FormatTime - Syntax & Usage | AutoHotkey
https://autohotkey.com/docs/commands/FormatTime.htm
Code: Select all
q:: ;convert dates - 'yyyyMMdd-XXXX' to 'yyMMdd XXXX'
vDate := "20060504-9999"
vDate := SubStr(StrReplace(vDate, "-", " "), 3)
MsgBox, % vDate
return
FormatTime - Syntax & Usage | AutoHotkey
https://autohotkey.com/docs/commands/FormatTime.htm
(Where YYYYMMDDHH24MISS is yyyyMMddHHmmss.) (Note: that's in reference to the *input* parameter, not the format parameter.)YYYYMMDD...
Leave this parameter blank to use the current local date and time. Otherwise, specify all or the leading part of a timestamp in the YYYYMMDDHH24MISS format.
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
Re: Simpel formattime
Jeeswg, simple:P I'm trying to learn string manipulation, but I think its hard. Maybe you can help me with another one after this
It worked like a charm :D
It worked like a charm :D
Re: Simpel formattime
Im going to post my other problem here to, since you guys where so awesome
Code: Select all
[Send, ^c
IfLessOrEqual,A_Now, EnvAdd, ymdhms, -6574, days
{
send,^+F
}
else
loop,4
{
send, ^+F
}
]/code]/code]
I trying to get THE code to preform a action of date is more then 18 years Ago.
Re: Simpel formattime
- I would do it like this, using a backport of the DateDiff function from AHK v2.
- Note: the dates must be in the appropriate format: 'all or the leading part of a timestamp in the YYYYMMDDHH24MISS format'.
- Note: the dates must be in the appropriate format: 'all or the leading part of a timestamp in the YYYYMMDDHH24MISS format'.
Code: Select all
q:: ;dates - are dates at least 18 years apart
vDate1 := 20180722120000 ;midday 2018-07-22
vList := "20010101,20000101"
Loop, Parse, vList, % ","
{
vDate2 := A_LoopField
;18 years ~= 18*365 days = 6570 days
;note: DateDiff does vDate1 subtract vDate2 (you could use Abs to get the absolute difference)
if (DateDiff(vDate1, vDate2, "D") > 6570)
MsgBox, % "over 18 years ago"
else
MsgBox, % "less than 18 years ago"
}
return
;commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=29689
DateDiff(DateTime1, DateTime2, TimeUnits)
{
EnvSub DateTime1, %DateTime2%, %TimeUnits%
return DateTime1
}
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
Re: Simpel formattime
The format Will be as before YYYYMMDD-XXXX, is that a problem with that coding? The last three digits are obselete in this context, I only need YYYYMMDD.
Re: Simpel formattime
If the hyphen and last 4 digits are unnecessary, you can crop them like this:
Code: Select all
q:: ;convert dates - 'yyyyMMdd-XXXX' to 'yyyyMMdd'
vDate := "20060504-9999"
vDate := SubStr(vDate, 1, -5)
MsgBox, % vDate
return
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
Re: Simpel formattime
hmm I did it like thisjeeswg wrote:If the hyphen and last 4 digits are unnecessary, you can crop them like this:
Code: [Select all]GeSHi © Codebox Plus
q:: ;convert dates - 'yyyyMMdd-XXXX' to 'yyyyMMdd'
vDate := "20060504-9999"
vDate := SubStr(vDate, 1, -5)
MsgBox, % vDate
retur
Code: Select all
vDate := "clipboard"
vDate := SubStr(vDate, 1, -5)
vList := clipboard
Loop, Parse, vList, % ","
{
vDate2 := A_LoopField
;18 years ~= 18*365 days = 6570 days
;note: DateDiff does vDate1 subtract vDate2 (you could use Abs to get the absolute difference)
if (DateDiff(vDate1, vDate2, "D") > 6570)
MsgBox, % "over 18 years ago"
else
MsgBox, % "less than 18 years ago"
}
And also a little daft question. To get it to work as I mentioned from the begining I just substitute "MSG box" with { send,^+F } andloop,4 { send, ^+F }
Re: Simpel formattime
This is probably more like what you want:
Code: Select all
q:: ;dates - is date at least 18 years ago
vDate1 := A_Now
;vDate2 := "20060504-9999"
Clipboard := ""
SendInput, ^c
ClipWait, 3
if ErrorLevel
{
MsgBox, % "error: failed to retrieve clipboard text"
return
}
vDate2 := Clipboard
if !RegExMatch(vDate2, "^\d{8}-\d{4}$") ;yyyyMMdd-XXXX
{
MsgBox, % "error: invalid datestamp:`r`n" vDate2
return
}
vDate2 := SubStr(vDate2, 1, -5)
;18 years ~= 18*365 days = 6570 days
;note: DateDiff does vDate1 subtract vDate2 (you could use Abs to get the absolute difference)
if (DateDiff(vDate1, vDate2, "D") > 6570)
MsgBox, % "over 18 years ago"
else
MsgBox, % "less than 18 years ago"
return
;commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=29689
DateDiff(DateTime1, DateTime2, TimeUnits)
{
EnvSub DateTime1, %DateTime2%, %TimeUnits%
return DateTime1
}
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
Re: Simpel formattime
jeeswg wrote:This is probably more like what you want:Code: Select all
q:: ;dates - is date at least 18 years ago vDate1 := A_Now ;vDate2 := "20060504-9999" Clipboard := "" SendInput, ^c ClipWait, 3 if ErrorLevel { MsgBox, % "error: failed to retrieve clipboard text" return } vDate2 := Clipboard if !RegExMatch(vDate2, "^\d{8}-\d{4}$") ;yyyyMMdd-XXXX { MsgBox, % "error: invalid datestamp:`r`n" vDate2 return } vDate2 := SubStr(vDate2, 1, -5) ;18 years ~= 18*365 days = 6570 days ;note: DateDiff does vDate1 subtract vDate2 (you could use Abs to get the absolute difference) if (DateDiff(vDate1, vDate2, "D") > 6570) MsgBox, % "over 18 years ago" else MsgBox, % "less than 18 years ago" return ;commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community ;https://autohotkey.com/boards/viewtopic.php?f=37&t=29689 DateDiff(DateTime1, DateTime2, TimeUnits) { EnvSub DateTime1, %DateTime2%, %TimeUnits% return DateTime1 }
awsome, now it does exactly what I want it to do. Im going to live test it tomorrow.
string manipulation is a bit tricky. you seem to get the hang of it. It should be possible to get it to work the clipbord to change text from for exampel: Mom: to Mom: 23132131561531
Re: Simpel formattime
- Check the documentation for InStr, SubStr, StrReplace, and look on the forum for examples of if statements.
E.g. if (var = "text")
E.g. if (var1 = var2)
E.g. if (var = "text")
E.g. if (var1 = var2)
Code: Select all
q::
vText := "Mom:"
if InStr(vText, "Mom:")
vText := "Mom: 23132131561531"
MsgBox, % vText
return
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
Re: Simpel formattime
Can I put another IF statement to make it do an action if var is text?jeeswg wrote:This is probably more like what you want:Code: Select all
q:: ;dates - is date at least 18 years ago vDate1 := A_Now ;vDate2 := "20060504-9999" Clipboard := "" SendInput, ^c ClipWait, 3 if ErrorLevel { MsgBox, % "error: failed to retrieve clipboard text" return } vDate2 := Clipboard if !RegExMatch(vDate2, "^\d{8}-\d{4}$") ;yyyyMMdd-XXXX { MsgBox, % "error: invalid datestamp:`r`n" vDate2 return } vDate2 := SubStr(vDate2, 1, -5) ;18 years ~= 18*365 days = 6570 days ;note: DateDiff does vDate1 subtract vDate2 (you could use Abs to get the absolute difference) if (DateDiff(vDate1, vDate2, "D") > 6570) MsgBox, % "over 18 years ago" else MsgBox, % "less than 18 years ago" return ;commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community ;https://autohotkey.com/boards/viewtopic.php?f=37&t=29689 DateDiff(DateTime1, DateTime2, TimeUnits) { EnvSub DateTime1, %DateTime2%, %TimeUnits% return DateTime1 }
Re: Simpel formattime
It depends on what you mean by 'text'. No numbers? Contains at least 1 letter? Contains at least one space? Or some other condition like that. If you can come up with some criteria, it should be doable.
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
Re: Simpel formattime
If i remember correctly, its at least one letter and maybe a space. How would one go by too implement that in the code? Im trying to learn the IF condition also, im trying to read att the hompage, but im having a hard time puzzeling it togheterjeeswg wrote:It depends on what you mean by 'text'. No numbers? Contains at least 1 letter? Contains at least one space? Or some other condition like that. If you can come up with some criteria, it should be doable.
Who is online
Users browsing this forum: doodles333, Google [Bot] and 250 guests