Comparing Dates

Get help with using AutoHotkey and its commands and hotkeys
Monoxide3009
Posts: 22
Joined: 09 Apr 2018, 15:53

Comparing Dates

19 Jul 2018, 12:45

I have seen MANY forum posts on this, so I apologize, but I cannot get what I am doing wrong even with some of those answers. I am still quite new, so any advice would help if extremely detailed. Do not worry about condescending =p

Right now, I am trying to compare a date pulled from an internal program to today's current date. I thought this would be a lot easier than it has been. I 'believe' the problem lies with the date being pulled internally is set as text.

My current code is:

Code: [Select all] [Download] GeSHi © Codebox Plus

var1 = %A_Now% ; current date
FormatTime, var1, %var1%, MM/dd/yyyy ; set to just date, no time
Send, %var1%`r ; confirm output
Sleep, 50
var2 = %clipboard% ; pulls "text" date as 07/15/2018 as test
Sleep, 50
FormatTime, var2, %var2%, MM/dd/yyyy ; does not convert to format properly, if this line removed, "date" is an output, but then EnvSub does not work.
Send, %var2%`r ; confirm output

EnvSub, var1, %var2%, days ; expcted outcome to be 4 with current date
MsgBox, %var1% ; currently has blank output


I have tried looking into ParseDate(), but my version does not recognize that as a function, and getting updates from IT here is like pulling teeth. Any help on getting this date function to work would be greatly appreciated.

My overall goal is to have an - if (datedifference > 40) {alternate route} - option within my current code. If there is a better/easier way to accomplish this, by all means, let me know.
Monoxide3009
Posts: 22
Joined: 09 Apr 2018, 15:53

Re: Comparing Dates

19 Jul 2018, 15:49

Playing around, I used a regex match to change the format of both dates to yyyymmdd then used EnvSub, and it seems to be working.

I am going to try to adapt this to the main script.

If anyone has suggestions or a better working process, please let me know still.

What I came up with:

var1 = %A_Now% ; current date
FormatTime, var1, %var1%, yyyyMMdd ; set to just date, no time
Send, %var1%`r ; confirm output
Sleep, 50
var2 = %clipboard% ; pulls "text" date as 07/15/2018
Sleep, 50
RegExMatch(var2, "(..)\/(..)\/(....)", var2)
Sleep, 50
var2 = %var23%%var21%%var22%
Sleep, 50
Send, %var2% ; confirmation

FormatTime, var2, %var2%, yyyyMMdd


EnvSub, var1, %var2%, days
MsgBox, %var1% ; currently has blank output
burque505
Posts: 526
Joined: 22 Jan 2017, 19:37

Re: Comparing Dates

19 Jul 2018, 18:36

Hi, this is an interesting topic. There are many ways to skin this cat. Another is below.
Note I didn't use the clipboard, I just set a variable to a date. For me regexes are still black magic, but I'm overjoyed when I get one that works.
I used RegExReplace and backreferences instead of RegExMatch. I'm not sure it matters.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Regards,
burque505

Return to “Ask For Help”

Who is online

Users browsing this forum: comvox, DarkACB, TAC109 and 52 guests