If var is a date, how? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: If var is a date, how?

Post by Krd » 30 Jun 2022, 07:20

Lol, wow guys :D


Edit:

I like Bingo and Bongo!

Emile HasKey
Posts: 27
Joined: 06 Mar 2022, 17:45

Re: If var is a date, how?

Post by Emile HasKey » 02 Jul 2022, 19:10

Another way.

Code: Select all

; check date is valid:
date1 := "13.12.2020"
date2 := "33.12.2020"
MsgBox % Is_dd_MM_yyyy(date1) ; True
MsgBox % Is_dd_MM_yyyy(date2) ; False
return

Is_dd_MM_yyyy(date)
{
	local date2
	if !RegExMatch(date, "^\d{2}\.\d{2}\.\d{4}$")
		return False

	date2 := Format("{3:04}{2:02}{1:02}", StrSplit(date, ".")*)
	if date2 is Time
		return True
	return False
}

Rohwedder
Posts: 7645
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: If var is a date, how?

Post by Rohwedder » 03 Jul 2022, 02:17

Emile HasKey's version varied:

Code: Select all

; check date is valid:
date1 := "13.12.2020"
date2 := "33.12.2020"
MsgBox % Is_dd_MM_yyyy(date1) ; True
MsgBox % Is_dd_MM_yyyy(date2) ; False
return

Is_dd_MM_yyyy(date)
{
	; local D ; this does not work!
	if !RegExMatch(date, "^(\d{2})\.(\d{2})\.(\d{4})$", D)
		return False

	D := D3 D2 D1
	if D is Time
		return True
	return False
}

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: If var is a date, how?

Post by Krd » 03 Jul 2022, 14:13

So many good AHK-ers here :)

RegEx is magic. Where to learn all these creepy things that do things I can not understand?

User avatar
boiler
Posts: 16954
Joined: 21 Dec 2014, 02:44

Re: If var is a date, how?

Post by boiler » 04 Jul 2022, 07:19

@Krd

https://regexone.com/ is a good place to learn RegEx in a step-by-step tutorial fashion.

https://regex101.com/ is a good place for building and testing your RegEx patterns and is a good reference in general.

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: If var is a date, how?

Post by Krd » 04 Jul 2022, 12:05

I would never be able to find them my self. So RegEx is not AHK-special thing? At least the one used in AHK? I have started with https://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm and I miss some more examples. Coding language is not so easy for a long timer noob :HeHe:

I liked the first link very much. Thank you boiler! :cookie:

User avatar
boiler
Posts: 16954
Joined: 21 Dec 2014, 02:44

Re: If var is a date, how?

Post by boiler » 04 Jul 2022, 14:21

Krd wrote: I would never be able to find them my self.
Both of those sites and many others are easily found with a simple google search.

Krd wrote: So RegEx is not AHK-special thing?
No, regular expressions predate AHK by lot.

Krd wrote: At least the one used in AHK?
No, AHK uses Perl Compatible Regular Expression (PCRE), which is a library used by many programming languages.

Post Reply

Return to “Ask for Help (v1)”