-
Notifications
You must be signed in to change notification settings - Fork 0
DateTools v0.1
Builds a date object, complete with methods for manipulating dates and times, via a programmer-friendly interface. Dates are automatically parsed from a variety of formats. When parsing dates, any missing date information is derived from the information provided or will be gathered from A_Now.
Note, this set of functions may not behave properly for dates before the 1600's.
Authotkey v1.1.22 +
#Include DateTools.ahk
Today := New date
Today.Format := "ddd, yyyy MM dd"
strMessage := "Today is '" . Today.Format . "'"
strMessage .= " and the time is '" . Today.Format("hh:mm:ss tt") . "'"
strMessage .= "`n`nFour Score and Seven Years ago was '"
MsgBox, % strMessage . Today.Add({Score:-4, Years:-7}) . "'"
DateTools.SyntaxExamples()
-
Provides full control over adding or subtracting all units of time from seconds to centuries.
-
With months or larger units of time, DateTools automatically deals with leapyear and last day of month paradoxes by selecting the actual last day of the month rather than moving into the next month.
For example:
- January 31 plus 1 month will equal Feburary 28 or Feburary 29 if it's a leap year
- January 31 plus 2 months will equal March 31
- January 31 plus 3 months will equal April 30
-
Calculate complex operations like:
-
4th Thursday in November
MyDate := New Date("Nov 1") MyDate.Format := "yyyy MMM dd, dddd MsgBox, % "Thansksgiving will be on '" . MyDate.Add({Thrusdays:4}) . "'" -
Second Tuesday after the First Sunday in June
MyDate := New Date("Jun 1") MyDate.Add({Sundays:1}) MyDate.Add({Tuesdays:2}) MsgBox, % "Second Tuesday after the First Sunday in June '" . MyDate.Format("yyyy MMM dd, ddd") . "'"
-
-
Calculate the amount of time between two dates
FirstDate := New Date SecondDate := New Date SecondDate.Add({Score:-1, Decades:1, Years:-1, Months:1, Days:-1, Hours:1, Minutes:-1 }) TimeSpan := FirstDate.TimeSpan(SecondDate) MsgBox, % DateTools.ReportOptions(TimeSpan)
-
-
Comparison functions that automatically evaluate dates in a given format.
-
Are two date times on the same day or month
MyDate:= New Date("20150125-185600") MsgBox, % (MyDate.IsEqual("20150125-120000") ? "same day" : "not the same date") MsgBox, % (MyDate.IsEqual("20150125-120000", "yyyyMM") ? "same Month" : "not the same Month") -
Is a given date between a date range
MyDate:= New Date("20200125") MyDate.Till := "20100125" MsgBox, % (MyDate.IsBetween("20150125-120000") ? "Is between" : "Is not between")
-
-
Reads most date formats and standardizes them into the autohotkey standard
yyyyMMddHHmmssformat.
Full description of the syntax is in the comments of the Class Date. And more complex examples are availble in Class Datetools.SyntaxExamples