Date format to United Kingdom

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zack0
Posts: 5
Joined: 20 Jan 2019, 11:02

Date format to United Kingdom

20 Jan 2019, 11:10

AHK Experts and Novices, was hoping you could help my date problem on my script here.

It calculates from the clipboard if over 16 or under 16 years old.

I want to format in the UK format like 01/01/2000 but i cannot find out how to do this.

If anyone can help me i would greatly appreciate it!

Code: Select all

; To get under 16 copy paste 20190407 and to test over 16 copy 20010407

Days:= A_Now
Days -= %Clipboard%,Days

If ( Days < 5840 )
   MsgBox, Under 16
Else
   MsgBox, Over 16
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Date format to United Kingdom

20 Jan 2019, 13:05

This perhaps?

Code: Select all

;where vDate is in yyyyMMddHHmmss format, or with some of the trailing numbers removed
vDate := 20010407
FormatTime, vDate, % vDate, dd/MM/yyyy
MsgBox, % vDate
Btw, because it's confusing, I'll just mention:
+= positive number [add days/seconds etc to date]
+= negative number [subtract days/seconds etc from date]
-= [get the difference (days/seconds etc) between dates]
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
zack0
Posts: 5
Joined: 20 Jan 2019, 11:02

Re: Date format to United Kingdom

20 Jan 2019, 15:46

Looks like this could work, will play around and reply with my results! :clap: thanks!
zack0
Posts: 5
Joined: 20 Jan 2019, 11:02

Re: Date format to United Kingdom

21 Jan 2019, 19:03

I have copied this but it does still not work.

To confirm all my clipboard data will be in the UK format.

e.g. 01012000 = over 16
e.g. 01012018 = under 16

If i enter either into the clipboard they both result in over 16.

Here is my code:

Code: Select all

Days:= A_Now

Days -= %Clipboard%,Days

FormatTime, Days, % Days, ddMMyyyy

If ( Days < 5840 )
   MsgBox, Under 16
Else
   MsgBox, Over 16
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Date format to United Kingdom

21 Jan 2019, 20:17

- All of these tasks are fairly doable, it's just a question of knowing exactly what you want. I think I know what you want now.
- In short, AutoHotkey date commands can only handle *input* dates of the form 'yyyyMMddHHmmss', or variants with some of the ending bits removed like 'yyyyMMdd'. However, when you *output* a date (via FormatTime), there are many possible date formats.

Code: Select all

Clipboard := "01012000"
;Clipboard := "01012018"
;Clipboard := "01/01/2000"
;Clipboard := "01/01/2018"

Date := Clipboard
Date := StrReplace(Date, "/") ;remove slashes
if !(StrLen(Date) = 8)
{
	MsgBox, % "error: invalid/unsupported date:`r`n" Date
	return
}
Date := RegExReplace(Date, "(..)(..)(....)", "$3$2$1") ;reorder digits to give 'yyyyMMdd' format
;MsgBox, % Date

Days := A_Now

Days -= Date, Days

if ( Days < 5840 )
   MsgBox, Under 16
else
   MsgBox, Over 16
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
zack0
Posts: 5
Joined: 20 Jan 2019, 11:02

Re: Date format to United Kingdom

22 Jan 2019, 00:57

Brilliant this works perfect for what i need to do! Thanks so much again :)
zack0
Posts: 5
Joined: 20 Jan 2019, 11:02

Re: Date format to United Kingdom

01 Feb 2019, 17:49

I have just realised there is a wee bug to this!

01/01/1018 in clipboard brings back under 16 :crazy:

Is there a fix to this?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Date format to United Kingdom

02 Feb 2019, 02:03

You can do an 'is date' check. To add it in I've rearranged the code somewhat. The check demands a year between 1601 and 9999.
If Var is Type - Syntax & Usage | AutoHotkey
https://autohotkey.com/docs/commands/IfIs.htm

Code: Select all

Clipboard := "01012000"
;Clipboard := "01012018"
;Clipboard := "01/01/2000"
;Clipboard := "01/01/2018"
;Clipboard := "01/01/1018"

Date := Clipboard
DateOrig := Date
Date := StrReplace(Date, "/") ;remove slashes
Date := RegExReplace(Date, "(..)(..)(....)", "$3$2$1") ;reorder digits to give 'yyyyMMdd' format
;MsgBox, % Date

if Date is date
	IsDate := 1
else
	IsDate := 0

if !IsDate || !(StrLen(Date) = 8)
{
	MsgBox, % "error: invalid/unsupported date:`r`n" DateOrig
	return
}

Days := A_Now
Days -= Date, Days

if (Days < 5840)
	MsgBox, Under 16
else
	MsgBox, Over 16
1018 gave 'Under 16' because the -= operator doesn't support a date before 1601, and gave a blank string, the blank string was considered less than 5840.

Code: Select all

Date := "10180101"
Days := A_Now
Days -= Date, Days
MsgBox, % "[" Days "]"
MsgBox, % (Days < 5840)

Date := "19180101"
Days := A_Now
Days -= Date, Days
MsgBox, % "[" Days "]"
MsgBox, % (Days < 5840)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: downstairs, Google [Bot], OrangeCat and 185 guests