COMPARE DATES

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
feliperrds
Posts: 8
Joined: 25 Mar 2019, 07:52

COMPARE DATES

27 Mar 2019, 14:18

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.
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: COMPARE DATES

27 Mar 2019, 14:29

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.
feliperrds
Posts: 8
Joined: 25 Mar 2019, 07:52

Re: COMPARE DATES

28 Mar 2019, 17:13

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
User avatar
Blue Kodiak
Posts: 26
Joined: 17 Mar 2019, 00:45

Re: COMPARE DATES

28 Mar 2019, 17:39

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?
feliperrds
Posts: 8
Joined: 25 Mar 2019, 07:52

Re: COMPARE DATES

28 Mar 2019, 17:46

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
User avatar
Blue Kodiak
Posts: 26
Joined: 17 Mar 2019, 00:45

Re: COMPARE DATES

28 Mar 2019, 18:45

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 
}
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: COMPARE DATES

29 Mar 2019, 04:14

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.
feliperrds
Posts: 8
Joined: 25 Mar 2019, 07:52

Re: COMPARE DATES

29 Mar 2019, 16:56

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)
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: COMPARE DATES

30 Mar 2019, 03:07

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?
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: COMPARE DATES

30 Mar 2019, 07:24

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Google [Bot] and 326 guests