Hello to Everyone
i need to compare two values (dates) but when i try it, they just compare the DAY.
So when i use this. { If Clipboard < %A_DD%/%A_MM%/%A_YYYY% } (02/04/2019 < 27/03/2019) the answer should be "false" but is "true" because it jus compare the day.
what should i've done.
COMPARE DATES
-
- Posts: 8
- Joined: 25 Mar 2019, 07:52
-
- Posts: 440
- Joined: 28 Apr 2018, 21:59
Re: COMPARE DATES
In order to compare the times you must use the YYYYMMDDHH24MISS timestamp if you want to use it in an if statement. You can format the Clipboard time using the FormatTime function https://autohotkey.com/docs/commands/FormatTime.htm. A_Now will give the standard timestamp that way you don't have to make it yourself. Then you can use If (Clipboard < A_Now) and in the If statement since it is expecting variables you don't need the %% around your variables.
-
- Posts: 8
- Joined: 25 Mar 2019, 07:52
Re: COMPARE DATES
I've formatted the date from DD/MM/YYYY to YYYYMMDD and compare with the actual date with the same format but doesn't work.
Macro1:
FormatTime, clipboard, %clipboard%, yyyyMMdd
FormatTime, clipboard, %clipboard%, yyyyMMdd
If clipboard < %A_yyyy%%A_MM%%A_dd%
{
MsgBox, 0, , old
}
MsgBox, 0, , new
Macro1:
FormatTime, clipboard, %clipboard%, yyyyMMdd
FormatTime, clipboard, %clipboard%, yyyyMMdd
If clipboard < %A_yyyy%%A_MM%%A_dd%
{
MsgBox, 0, , old
}
MsgBox, 0, , new
- Blue Kodiak
- Posts: 26
- Joined: 17 Mar 2019, 00:45
Re: COMPARE DATES
But what was on the clipboard?
Was it a valid date that could be used in the FormatTime function?
-
- Posts: 8
- Joined: 25 Mar 2019, 07:52
Re: COMPARE DATES
some random dates older or not, but formated in DD/MM/YYYY so i formated in YYYYMMDD to compare if is more older then a actual date or not
- Blue Kodiak
- Posts: 26
- Joined: 17 Mar 2019, 00:45
Re: COMPARE DATES
It will need to be in YYYYMMDDHH24MISS order in the clipboard for TimeFormat to recognise it as a date
Also you may have to remove any formatting
Also you may have to remove any formatting
Code: Select all
ClipVar = %Clipboard% ; remove formatting
FormatTime, ClipVar , ClipVar , yyyyMMdd
FormatTime, Today, A_Now, yyyyMMdd
If (ClipVar < Today) ; If before last midnight, i.e., not today
{
MsgBox Old
}
Else
{
MsgBox New
}
Re: COMPARE DATES
FormatTime expects its input value (parameter 2) as YYYYMMDDHH24MISS timestamp or YYYYMMDD in your case. One option:
Ths built-in variable Clipboard always contains plain text and never formatting.
Code: Select all
#NoEnv
Clipboard := "29/03/2019"
ClipDate := RegExReplace(Clipboard, "(\d\d)/(\d\d)/(\d{4})", "$3$2$1")
MsgBox, %ClipDate%
Clipboard := ""
ExitApp
-
- Posts: 8
- Joined: 25 Mar 2019, 07:52
Re: COMPARE DATES
sorry, i am new in programmation.
but i need that a value inside the clipboard (DD/MM/YYYY) format in a (YYYYMMDD) so when i press Ctrl+V it ill paste the same value formatted (YYYYMMDD)
but i need that a value inside the clipboard (DD/MM/YYYY) format in a (YYYYMMDD) so when i press Ctrl+V it ill paste the same value formatted (YYYYMMDD)
Re: COMPARE DATES
feliperrds wrote:i need to compare two values (dates) but when i try it, they just compare the DAY.
Code: Select all
#NoEnv
; Clipboard contains: 24/03/2019
; A_Now is: 20190330085929
ClipDate := RegExReplace(Clipboard, "(\d\d)/(\d\d)/(\d{4})", "$3$2$1") ; 20190324
NowDate := SubStr(A_Now, 1, 8) ; 20190330
If (ClipDate < NowDate)
{
; What shall happen then?
}
Else
{
; What shall happen otherwise?
}
; What shall happen in both cases?
Re: COMPARE DATES
Nice RegEx. Ive been wondering how to reorder dates like that and was wasting time with substr and complex things. I like the RegEx and the usage of patterns
Who is online
Users browsing this forum: No registered users and 207 guests