Function Calculating Timespan in Years, Months, and Days

Post your working scripts, libraries and tools for AHK v1.1 and older
Lawyer_ahk
Posts: 3
Joined: 30 Aug 2022, 18:59

Re: Function Calculating Timespan in Years, Months, and Days

31 Aug 2022, 05:28

@gregster
Thank you , Sir. :)
carno
Posts: 265
Joined: 20 Jun 2014, 16:48

Re: Function Calculating Timespan in Years, Months, and Days

11 Sep 2022, 23:39

This counts Days between two dates:

Code: Select all

#SingleInstance Force ; Ensures that only the last executed instance of script is running
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases

Gui, Add, Text,, Prior Date:
Gui, Add, Text,, Post Date:
Gui, Add, Edit, vPr ym ; The ym option starts a new column of controls
Gui, Add, Edit, vpo
Gui, Add, Button, default, OK ; The label ButtonOK (if it exists) will run when the button is pressed
Gui, Show, w350, Enter Date in Format: YYYYMMDD
Return ; End of auto-execute section. The script is idle pending user's action

GuiClose:
ButtonOK:
Gui, Submit ; Save input from the user to each control's associated variable
EnvSub, po, %pr%, days

years := po // 365
remain_days := mod(po, 365)

months := remain_days // 30 ; Month taken as 30 days
remain_days := mod(remain_days, 30)

fortnights := remain_days // 15 ; Fortnight taken as 15 days
remain_days := mod(remain_days, 15)

weeks := remain_days // 7
days := mod(remain_days, 7 )

MsgBox % "Total days in between: " . po . "`n`n" . "Years: " . years . "`n" . "Months: " . months . "`n" . "Fortnights: " . fortnights . "`n" . "Weeks: " . weeks . "`n" . "Days: " . days

Clipboard := po

ExitApp

Esc::ExitApp

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: yxldh and 52 guests