comparing dates

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
prakashG
Posts: 24
Joined: 21 May 2020, 15:49

comparing dates

29 May 2020, 10:00

EC_date.txt file has dates as below:

2020-05-26
2020-05-27
2020-05-28
2020-05-29
2020-06-01
2020-06-02
2020-06-03

I want the read date to match with current date.
But the match is not happening.


Code: Select all

#EscapeChar `

FormatTime, TimeString,currentdatetime, yyyy-MM-dd
MsgBox The current date (long format) is %TimeString%.

FileRead,File1,Y:\EC_date.txt
i := 0

Loop,Parse,File1, `n
{
	i := i + 1
	Line1 := A_LoopField
			    
	If (Line1 = TimeString )
		{
		msgbox, i is %i%
		Break		
		}
}
Return
Last edited by prakashG on 29 May 2020, 10:29, edited 1 time in total.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: comparing dates

29 May 2020, 10:17

Hi Prakash,

Remove the return inside the loop and place it outside the loop after }.
As is, the loop won't iterate more than once because of the return
My Scripts and Functions: V1  V2
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: comparing dates

29 May 2020, 10:21

@SKAN , thanx

Code: Select all

FormatTime, TimeString,currentdatetime, yyyy-MM-dd
File1=
(
2020-05-26
2020-05-27
2020-05-28
2020-05-29
2020-06-01
2020-06-02
2020-06-03
)
i=0
Loop,Parse,File1, `n,`r
{
i++
x:=a_loopfield
if (x=Timestring)
  break
}
msgbox,Line-%i%=%x%
exitapp
prakashG
Posts: 24
Joined: 21 May 2020, 15:49

Re: comparing dates

29 May 2020, 10:23

Tried that. Actually my code has return outside, but while posting here, i made mistake.
anyway, the If (Line1 = TimeString ) code is not working. I suppose it should be simple string match (date as a string). But not working.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: comparing dates

29 May 2020, 10:24

prakashG wrote:
29 May 2020, 10:23
Tried that. Actually my code has return outside, but while posting here, i made mistake.
anyway, the If (Line1 = TimeString ) code is not working. I suppose it should be simple string match (date as a string). But not working.
Update your post then.
My Scripts and Functions: V1  V2
prakashG
Posts: 24
Joined: 21 May 2020, 15:49

Re: comparing dates

29 May 2020, 10:30

edited the code.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: comparing dates

29 May 2020, 10:37

prakashG wrote: edited the code.
Good.

Line1 has a trailing `r and hence not matching the TimeString

Change your loop to Loop, Parse, File1, `n, `r
My Scripts and Functions: V1  V2
prakashG
Posts: 24
Joined: 21 May 2020, 15:49

Re: comparing dates

29 May 2020, 10:52

It worked. Thank you.
May i know how did you debug that `r ? is there a way to see all control characters in text file?
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: comparing dates

29 May 2020, 11:06

prakashG wrote: It worked. Thank you.
May i know how did you debug that `r ? is there a way to see all control characters in text file?
I use my own function to view binary content. You may use a Hex viewer/editor to view any file.
But when a string comparison fails, just do something like

Code: Select all

MsgBox % StrLen(Line1)
to make sure there are no extra chars in source string.
My Scripts and Functions: V1  V2
prakashG
Posts: 24
Joined: 21 May 2020, 15:49

Re: comparing dates

29 May 2020, 13:03

:clap: :clap: :clap:
thank you
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: comparing dates

29 May 2020, 14:05

@prakashG You can use :arrow: Notepad2 (free) that offers the option to show (and create) these line-endings (EOL-characters: [`r|`n`r|`n].
gregster
Posts: 9022
Joined: 30 Sep 2013, 06:48

Re: comparing dates

29 May 2020, 14:12

Afaik, most editors that are actually used for programming have an option to show these EOL characters.

Generally, I like this page for examining strings for invisible characters: https://www.soscisurvey.de/tools/view-chars.php

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww, PsysimSV, uchihito and 207 guests