daysBeetweenTimeStamps(t1,t2)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

daysBeetweenTimeStamps(t1,t2)

24 Apr 2018, 10:18

waiting for your better, faster solution. in my actually useCase its okay. works

Code: Select all

daysBeetweenTimeStamps(t1,t2){
      t2Backup := t2
      if(t1>t2){
            t2:=t1
            t1:=t2Backup
      } 
      index := 0
      i := substr(t1,1,8)
      while(i<>t2){
            i += 1, days 
            i := substr(i,1,8)
            Tooltip,%i% `n (from: %A_LineFile%~%A_LineNumber%) 
            ;Msgbox,%i%`n %A_Now% (%A_LineFile%~%A_LineNumber%) 
            ;Msgbox,%A_Index%: %i%`n  (%A_LineFile%~%A_LineNumber%) 
            index := A_Index
      }
      ;Msgbox,%index%: %t1% - %t2% `n (%A_LineFile%~%A_LineNumber%) 
      return index
      ;20180424
      t2 = 20180424
      t1 = 20180501
      ; daysBeetweenTimeStamps(t1,t2)
}
just me
Posts: 9456
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: daysBeetweenTimeStamps(t1,t2)

24 Apr 2018, 10:42

Code: Select all

TE := 20180501 ; end date
TS := 20180424 ; start date

Days := TE
Days -= TS, D
MsgBox, %Days%
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: daysBeetweenTimeStamps(t1,t2)

24 Apr 2018, 11:00

AHK v2 has a DateDiff function which can be recreated in AHK v1.

Code: Select all

q::
TE := 20180501 ; end date
TS := 20180424 ; start date

Days := DateDiff(TE, TS, "D")
MsgBox, % Days
return

/*
;commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=29689

DateAdd(DateTime, Time, TimeUnits)
{
    EnvAdd DateTime, %Time%, %TimeUnits%
    return DateTime
}
DateDiff(DateTime1, DateTime2, TimeUnits)
{
    EnvSub DateTime1, %DateTime2%, %TimeUnits%
    return DateTime1
}
FormatTime(YYYYMMDDHH24MISS:="", Format:="")
{
    local OutputVar
    FormatTime OutputVar, %YYYYMMDDHH24MISS%, %Format%
    return OutputVar
}
*/
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
carno
Posts: 265
Joined: 20 Jun 2014, 16:48

Re: daysBeetweenTimeStamps(t1,t2)

30 Jun 2018, 23:03

Counting Business Days (Excluding Saturdays and Sundays)

Code: Select all

CountBusinessDays(Days) {
   BDays := 0
   While (BDays < Days) {
      var1 += 1, D
      FormatTime, WDay, %var1%, WDay
      If (WDay <> 1) && (WDay <> 7) ; Excluding Saturdays and Sundays
         BDays++
   }
   FormatTime, Result, %var1%, MMM-dd-yy
   Return Result
}
Guest

Re: daysBeetweenTimeStamps(t1,t2)

01 Jul 2018, 02:32

time() by HotKeyIt, source and examples:
http://www.autohotkey.com/board/topic/4 ... een-dates/
Time(to,from="",units="d",params="")

to and from can be in following format (from will be A_Now if empty):
- 20090101...
- 20090101000000
- Apr-04-2009 or Apr-04 for current year
- 01-01-2009 or 01-01 for current year
Units (output units) can be d=days, h=hours, m=minutes, s=seconds
params can be W,D,H,M,S
- W = WeeksDay to include, e.g. W2-6 (mon-fri) or W1.7 (exclude weekends)
- D = Day of Month to include, e.g. e D1-5 (to exclude D1.2.3)
- B = Bank holiday to exclude, e.g. B0101.3112
- H = Hours to include, e.g. H8-17 (to exclude use H0.1.2...)
- M = Minutes to include, e.g. M0-30 (to exclude use M0.1.2...)
- S = Seconds to include, e.g. S0-30 (to exclude use S0.1.2...)

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 158 guests