Page 1 of 1

COMPARE DATES

Posted: 27 Mar 2019, 14:18
by feliperrds
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.

Re: COMPARE DATES

Posted: 27 Mar 2019, 14:29
by MannyKSoSo
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.

Re: COMPARE DATES

Posted: 28 Mar 2019, 17:13
by feliperrds
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

Re: COMPARE DATES

Posted: 28 Mar 2019, 17:39
by Blue Kodiak
feliperrds wrote:
28 Mar 2019, 17:13
FormatTime, clipboard, %clipboard%, yyyyMMdd
But what was on the clipboard?
Was it a valid date that could be used in the FormatTime function?

Re: COMPARE DATES

Posted: 28 Mar 2019, 17:46
by feliperrds
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

Re: COMPARE DATES

Posted: 28 Mar 2019, 18:45
by Blue Kodiak
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

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

Posted: 29 Mar 2019, 04:14
by just me
FormatTime expects its input value (parameter 2) as YYYYMMDDHH24MISS timestamp or YYYYMMDD in your case. One option:

Code: Select all

#NoEnv
Clipboard := "29/03/2019"
ClipDate := RegExReplace(Clipboard, "(\d\d)/(\d\d)/(\d{4})", "$3$2$1")
MsgBox, %ClipDate%
Clipboard := ""
ExitApp
Ths built-in variable Clipboard always contains plain text and never formatting.

Re: COMPARE DATES

Posted: 29 Mar 2019, 16:56
by feliperrds
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)

Re: COMPARE DATES

Posted: 30 Mar 2019, 03:07
by just me
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

Posted: 30 Mar 2019, 07:24
by DRocks
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