Convert dates to different format(s)

Discussion, questions and support.
Post Reply
jvroom
Posts: 28
Joined: Apr 30th, ’21, 12:37

Post by jvroom » Jan 26th, ’22, 21:06

Hi Everyone,

I'm seeking a solution to the following...

Background: While handling customer service calls I frequently find myself collecting dates from callers, and then later having to copy/paste/re-enter dates into various form fields. However, I need to enter the dates in different formats in different places.

For example, I have to enter a date in this date format 01/01/2022 in one place, then this format Jan 1, 2022 (3 letter month) in another place, 1/1/2022 in another place, January 1, 2022, in another.

I'm looking/hoping for a solution where I can type and/or copy a date (preferably in any format) and then be able to somehow select an alternative date format and be able to paste the converted date where needed. Or, type a date followed by a (trigger key?) that would then offer me the option of selecting the desired alternative date format, and once selected, would be copied to the clipboard so it can be pasted where needed. - Or, some other solution?

Thanks for a solution to the above issue/topic/problem
User avatar
Marko
Posts: 1483
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jan 30th, ’22, 20:07

If you would capture the date by using the Selection Form macro, then you can change it to any format by using a script (Type: Command) and FormatTime command.
https://www.autohotkey.com/docs/commands/FormatTime.htm

After that you could create a simple paste gui with the different formats. I can try making an example when I will have some time.
User avatar
Marko
Posts: 1483
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Feb 1st, ’22, 21:29

Quick idea...

Code: Select all

if WinExist("FastKeys Paste"){
	Gui, dates:Destroy
	return
}
gui, dates:default
gui, destroy
gui, font, s9, Segoe UI
gui, margin, 15, 15
gui, add, DateTime, xm vMyDate w200 gUpdateDate, 
gui, add, edit, xm w200 vDate1, 
gui, add, button, x+6 yp w75 h25 vButton1 gGDPaste, Paste
gui, add, edit, xm w200 vDate2, 
gui, add, button, x+6 yp w75 h25 vButton2 gGDPaste, Paste
gui, add, edit, xm w200 vDate3, 
gui, add, button, x+6 yp w75 h25 vButton3 gGDPaste, Paste
gosub UpdateDate
Gui, -MaximizeBox -MinimizeBox +AlwaysOnTop +E0x08000000
gui, show,, FastKeys Paste
return

UpdateDate:
gui, submit, nohide
FormatTime, Date1, %MyDate%, MMM dd, yyyy
GuiControl,, Date1, %Date1%
FormatTime, Date2, %MyDate%, MM/dd/yyyy 
GuiControl,, Date2, %Date2%
FormatTime, Date3, %MyDate%, MMMM dd, yyyy
GuiControl,, Date3, %Date3%
return

GDPaste:
foo:=SubStr(A_GuiControl,-0)
gui, submit, nohide
sendinput, % Date%foo%
return
jvroom
Posts: 28
Joined: Apr 30th, ’21, 12:37

Post by jvroom » Feb 7th, ’22, 05:36

Thanks Marko!

The script is cool and works :)

Question.
Is there a way that the solution you created could be modified so that I could manually enter/paste a date into your solution's first date control/field instead of having to use the form's current first (date selector(?)) control/field?

Issue: During a call, I'll ask, "what's your date of birth" and need to quickly type the date given into a data field in the application I'm using.

Once I have the date captured/entered, I want to be able to easily get the date from the form field where the date was entered into the solution you made so that the date can be converted into the various formats. Can you think of a faster way of being able to paste or type a date into the first field of your form? Maybe there's a trick to entering a date into the first field on your date form that I'm not aware of?

Hmm. If I copied the date that the caller gave me and then could paste it into the first field of your solution, could the pasted date be automatically converted into the other date formats?

I love having the different formats ready/available to be pasted once the conversions are made.
User avatar
Marko
Posts: 1483
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Feb 8th, ’22, 17:24

Isn't the quickest to enter the date into the provided field by typing the numbers and/or using up/down keys to change the date? Press right/left to go to the next field.
jvroom
Posts: 28
Joined: Apr 30th, ’21, 12:37

Post by jvroom » Feb 9th, ’22, 05:06

Hi Marko,

Thanks for the date field navigation tips. Helpful. (I feel silly now. I was using the down/drop-down arrow on the first field.)

That said...
I do think that it would be faster if, after initially entering a date in the application that I'm capturing caller info in, I could just copy the entered date and then paste it into your solutions first date filed where it would then be converted into alternative date formats.

Ideally, I'd like to be able to copy a date, initially captured in any format (or any of the 3 formats currently being used in your solution), and then paste it into your solution first field where it would then be converted into the alternative date formats.

As an aside...I totally respect you and others who are coders/scriptwriters. It's such a great skill to have.

Thanks!
User avatar
Marko
Posts: 1483
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Feb 10th, ’22, 20:03

jvroom wrote:
Feb 9th, ’22, 05:06
Ideally, I'd like to be able to copy a date, initially captured in any format
Not sure this is a good idea, how can computer know which format was pasted? mm/dd or dd/mm or others?
jvroom
Posts: 28
Joined: Apr 30th, ’21, 12:37

Post by jvroom » Feb 10th, ’22, 20:31

Hmm. I'm not sure, maybe via some sort of if/then/else full, or partial pattern match?

Most often, the initially captured date format is ##/##/#### OR Jan 1, 2022
3 text characters (month)
No leading zero (day)
Comma
4 digit year
Post Reply