Format typed date

Get help with using AutoHotkey and its commands and hotkeys
hannahelappin
Posts: 52
Joined: 01 Jun 2019, 09:02

Format typed date

02 Jun 2019, 16:03

Hi, I use a script to enter current date. However is there a way to format a typed date. So if I type 030619 will send 03/06/19. Or even better if possible 03/06/19 (Mon). So format date / and have the day in brackets.

Would you send control A, then copy to clipboard and paste formatted somehow?

Manny thanks
swagfag
Posts: 3061
Joined: 11 Jan 2017, 17:59

Re: Format typed date

02 Jun 2019, 16:14

Code: Select all

FormatTime formatted, % convert("030619"), dd/MM/yyyy (ddd)
MsgBox % formatted

convert(ddmmyy) {
	RegExMatch(ddmmyy, "(..)(..)(..)", $)
	return "20" $3 $2 $1
}
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Format typed date

02 Jun 2019, 17:45

Here's a full script, select the 6-digit date, then press Ctrl+Q.

Code: Select all

^q:: ;convert date - 'ddMMyy' to 'dd/MM/yy (ddd)'
Clipboard := ""
SendInput, ^c
ClipWait, 3
if ErrorLevel
{
	MsgBox, % "error: failed to retrieve clipboard text"
	return
}
vDate := Clipboard
if !RegExMatch(vDate, "^\d{6}$")
{
	MsgBox, % "error: invalid date: " vDate
	return
}
vDate := RegExReplace(vDate, "(..)(..)(..)", "20$3$2$1")
FormatTime, vDate, % vDate, dd/MM/yy (ddd)
;FormatTime, vDate, % vDate, ddd dd MMM yyyy ;an alternative
SendInput, % vDate
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
hannahelappin
Posts: 52
Joined: 01 Jun 2019, 09:02

Re: Format typed date

03 Jun 2019, 07:44

Hi, thats superb thanks so much.

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Google [Bot], Odlanir, pn4265 and 243 guests