Page 1 of 1

Format typed date

Posted: 02 Jun 2019, 16:03
by hannahelappin
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

Re: Format typed date

Posted: 02 Jun 2019, 16:14
by swagfag

Code: Select all

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

convert(ddmmyy) {
	RegExMatch(ddmmyy, "(..)(..)(..)", $)
	return "20" $3 $2 $1
}

Re: Format typed date

Posted: 02 Jun 2019, 17:45
by jeeswg
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

Re: Format typed date

Posted: 03 Jun 2019, 07:44
by hannahelappin
Hi, thats superb thanks so much.