;-- TIME_STAMP 2020-01-30 21:28:59 v 0.2 #cs Dt.au3 Funktionssammlung zum Rechnen mit Datumswerten. Umfangreiche individuelle Formatierungsmöglichkeiten von Datumswerten (gut einsetzbar für Textbausteine u. ä.). Nicht berücksichtigt als Vorformatierung habe ich die Normschreibweisen JJJJ-Www-T (Jahr-KW-TagNumInWoche) und ähnliche, da diese ausserhalb der Norm unüblich sind. Es sind ausschliesslich Funktionen zur Operation mit Datumswerten enthalten, Zeitberechnung ist nicht gewollt und nicht enthalten. • Ist ein Datum zu übergeben ($_sDate), so ist immer die Form "YYYY/MM/DD" zu verwenden. Konvertierung aus Einzelwerten ist mit "_Dt_YMDToCalcDate" möglich. >> functions: # _Dt_Add($_sType, $_iCount, $_sDate, $_sLocale='') ; Addiert (Subtrahiert mit negativem $_iCount) eine Anzahl zu/von einem Startdatum. Typ: ('D'=Tag, 'M'=Monat, 'Y'=Jahr, 'w'=Woche). Ausgabe optional formatiert. # _Dt_CountWeeks($_sDate) ; Gibt für ein gegebenes Jahr (od. Datum) die Anzahl der Wochen dieses Jahres zurück # _Dt_DateToDayNumYear($_sDate) ; Gibt das Datum als n-ter Tag im Jahr zurück # _Dt_DayName($_sDate, $_iType=0) ; Gibt das Datum als Wochentagname zurück. $_iType: 0/1=short/long, Mo..So/Montag..Sonntag # _Dt_DayNumOfWeekToName($_iDayNum, $_iType = 0) ; Gibt für die Wochentagsnummer den Namen des Tages in lokaler Kurz-/Langform zurück # _Dt_DayNumWeek($_sDate) ; Gibt das Datum als n-ter Tag der Woche wieder (1..7 = Mo..So) # _Dt_DayNumYearToDate($_iYear, $_iDayNum) ; Gibt n-ten Tag eines Jahres als Datum zurück # _Dt_Diff($_sType, $_sDateStart, $_sDateEnd) ; Gibt die Differenz zwischen zwei Datumswerten zurück. Typ: ('D'=Tag, 'M'=Monat, 'Y'=Jahr, 'w'=Woche) # _Dt_Format($_sDate, $_sLocale=0) ; Gibt ein Datum formatiert zurück. Standard (0) = ShortLocale. Für $_sLocale kann benutzerdefinierte Definition übergeben werden. (s. "string format") # _Dt_IsLeapYear($_vYear) ; Prüft gegebenes Jahr (od. Datum) auf Schaltjahr (True/False) # _Dt_IsValid($_sDate) ; Prüft Datum '[YY]YY/MM/DD' auf Gültigkeit. Wenn gültig - Rückgabe Datumsstring als 'YYYY/MM/DD', sonst: 0 # _Dt_ShortLocaleToCalcDate($_sDate) ; Gibt Datum des Formats ShortLocale als Datum 'YYYY/MM/DD' zurück # _Dt_Today($_sLocale='') ; Gibt das Datum für Heute zurück 'YYYY/MM/DD', wahlweise formatiert (s. "string format") # _Dt_WeekNum($_sDate, $_bRetArray=False) ; Gibt das Datum als Wochennummer od. Array mit [KW,Kalenderjahr_der_KW] zurück # _Dt_YMDToCalcDate($_iYear, $_iMonth, $_iDay) ; Gibt die übergebenen Einzelwerte des Datums als Rechen-Datum ($_sDate in den anderen Funktionen) zurück >> string format: d = Tag nummerisch ein- od. zweistellig ohne füllende Vorzeichen dd = Tag nummerisch zweistellig (ggf. mit Vornull) w = Wochennummer ein- od. zweistellig ohne füllende Vorzeichen sw = Wochennummer zweistellig (ggf. mit Vor-Space) ww = Wochennummer zweistellig (ggf. mit Vornull) ddd = Wochentag in Kurzform (Mo, Di, ..) dddd = Wochentag in Langform (Montag, Dienstag, ..) M = Monat nummerisch ein- od. zweistellig ohne füllende Vorzeichen MM = Monat nummerisch zweistellig (ggf. mit Vornull) MMM = Monatsname in Kurzform (Jan, Feb, ..) MMMM = Monatsname in Langform (Januar, Februar, ..) y = Jahr einstellig yy = Jahr zweistellig (ggf. mit Vornull) yyyy = Jahr vierstellig Texte innerhalb Userformat mit Stringbegrenzern einfassen: "ww'TEXT'yyyy" Stringbegrenzer innerhalb eines Textes maskieren: "ww'TEXT\'In-Anführungszeichen\'TEXT'yyyy" Wenn Stringbegrenzer im Text identisch mit Stringbegrenzer des Formatstrings - zusätzlich doppeln: "ww'TEXT\""In-dopp.-Anführungszeichen\""'yyyy" >> example format: "'KW: 'w ddd, d.MMMM yy" ==> "KW: 3 Dienstag, 16. Januar 18" ; WochenNr ein/zweistellig ohne Vor-zeichen, Tag lang, Monat lang "'KW: 'ww dd, d.MMMM yy" ==> "KW: 03 Die, 16. Januar 18" ; WochenNr zweistellig mit Vor-Null, Tag kurz, Monat lang "'KW: 'sw dd, d.MMMM yy" ==> "KW: 3 Die, 16. Januar 18" ; WochenNr zweistellig mit Vor-Space, Tag kurz, Monat lang "'KW: 'w dd, d.MMM yy" ==> "KW: 3 Die, 16. Jan 18" ; WochenNr ein/zweistellig ohne Vor-zeichen, Tag kurz, Monat kurz "'KW: 'w dd, d.MM.yyyy" ==> "KW: 3 Die, 16.01.2018" ; WochenNr ein/zweistellig ohne Vor-zeichen, Tag kurz, Monat numerisch >> internal: __IsLeapYear __DaysInYear __IsValid __DayArrayMonth __DateToDayNumInYear __DayNumInYearToDate __DateAsDayNumOfWeek __DateAsDayNameOfWeek __DateGetWeekNum __YearCountWeeks __DateToArray __DayDiff __WeekDiff __MonthDiff __YearDiff __DayAdd __WeekAdd __MonthAdd __YearAdd __GetLocaleInfo __GetDayLocale __GetMonthLocale __DateFormat __ShortLocaleToCalcDate __GetTwoDigitYearMax #ce ; Bei Angabe einer 2-stelligen Jahreszahl bestimmt $I2DIGITBORDER die Grenze zur Zuweisung 19xx oder 20xx ; Info aus: 'HKEY_CURRENT_USER\Software\Policies\Microsoft\Control Panel\International\Calendars\TwoDigitYearMax' ; Fehlt der Eintrag wird der Windows-Standard 2029 verwendet (0..29 = 20xx, 30..99 = 19xx) Global Const $I2DIGITBORDER = __GetTwoDigitYearMax() ; Covern der Funktion StringFormat() Global $SF = StringFormat ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_Add ; Description ...: Addiert/Subtrahiert eine Anzahl zu/von einem Startdatum. ; Syntax ........: _Dt_Add($_sType, $_iCount, $_sDate[, $_sLocale = '']) ; Parameters ....: $_sType - Einheit für Differenz ('D'=Tag, 'M'=Monat, 'Y'=Jahr, 'w'=Woche) ; $_iCount - Zu addierender Wert (negativ für Subtraktion) der Einheit. ; $_sDate - Datum 'YYYY/MM/DD'. ; $_sLocale - [optional] Die Ausgabe kann formatiert werden. Standard ist '' = keine Formatierung. ; Details s. Dateikopf "string format". ; Return values .: Success Das neue Datum. Optional im angegebenen Format. ; Failure 0 @error = 1 Datum ungültig ; @error = 2 Typ ungültig ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_Add($_sType, $_iCount, $_sDate, $_sLocale='') If Not StringInStr(' D M Y w ', ' ' & $_sType & ' ') Then Return SetError(2,0,0) Local $sResult Switch $_sType Case 'D' $sResult = __DayAdd($_iCount, $_sDate) Case 'M' $sResult = __MonthAdd($_iCount, $_sDate) Case 'Y' $sResult = __YearAdd($_iCount, $_sDate) Case 'w' $sResult = __WeekAdd($_iCount, $_sDate) EndSwitch Return ($_sLocale == '' ? $sResult : __DateFormat($sResult, $_sLocale)) EndFunc ;==>_Dt_Add ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_CountWeeks ; Description ...: Gibt für ein gegebenes Jahr (od. Datum) die Anzahl der Wochen dieses Jahres zurück ; Syntax ........: _Dt_CountWeeks($_vYear) ; Parameters ....: $_vYear - Jahr oder Datum 'YYYY/MM/DD'. ; Return values .: Success Anzahl Wochen dieses Jahres ; Failure 0 @error = 1 Datum ungültig ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_CountWeeks($_vYear) If StringInStr($_vYear, '/') Then Local $aDate = __DateToArray($_vYear) If Not @error Then $_vYear = $aDate[0] Else Return SetError(1,0,0) EndIf EndIf Return __YearCountWeeks($_vYear) EndFunc ;==>_Dt_CountWeeks ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_DateToDayNumYear ; Description ...: Gibt das Datum als n-ter Tag im Jahr zurück ; Syntax ........: _Dt_DateToDayNumYear($_sDate) ; Parameters ....: $_sDate - Datum 'YYYY/MM/DD' ; Return values .: Success n-ter Tag im Jahr ; Fehler 0 @error = 1 Datum ungültig ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_DateToDayNumYear($_sDate) Return __DateToDayNumInYear($_sDate) EndFunc ;==>_Dt_DateToDayNumYear ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_DayName ; Description ...: Gibt das Datum als Wochentagname zurück. ; Syntax ........: _Dt_DayName($_sDate[, $_iType = 0]) ; Parameters ....: $_sDate - Datum 'YYYY/MM/DD' ; $_iType - [optional] Rückgabetyp 0/1=short/long. Standard ist 0. ; Return values .: Success Mo..So/Montag..Sonntag ; Failure 0 @error = 1 Datum ungültig ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_DayName($_sDate, $_iType=0) Return __DateAsDayNameOfWeek($_sDate, ($_iType = 1 ? 1 : 0)) EndFunc ;==>_Dt_DayName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_DayNumOfWeekToName ; Description ...: Gibt für die Wochentagsnummer den Namen des Tages in lokaler Kurz-/Langform zurück ; Syntax ........: _Dt_DayNumOfWeekToName($_iDayNum[, $_iType = 0]) ; Parameters ....: $_iDayNum - Wochentagsnummer (1..7). ; $_iType - [optional] Rückgabetyp 0/1=short/long. Standard ist 0. ; Return values .: Success Kurz- oder Langname des Wochentages ; Failure 0 @error = 1 Tagesnummer ungültig ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_DayNumOfWeekToName($_iDayNum, $_iType=0) If $_iDayNum < 1 Or $_iDayNum > 7 Then Return SetError(1,0,0) Switch $_iType Case 0 Return __GetDayLocale($_iDayNum) Case 1 Return __GetDayLocale($_iDayNum, 1) EndSwitch EndFunc ;==>_Dt_DayNumOfWeekToName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_DayNumWeek ; Description ...: Gibt das Datum als n-ter Tag der Woche wieder ; Syntax ........: _Dt_DayNumWeek($_sDate, $_bCalc=False) ; Parameters ....: $_sDate - Datum 'YYYY/MM/DD' ; ...............: $_bCalc - [optional] Für Datumsberechnungen kann es sinnvoll sein den Rückgabewert in der Form 0..6 = So..Sa zu erhalten. ; Return values .: Success 1..7 = Mo..So (mit $_bCalc=True 0..6) ; Failure 0 @error = 1 Datum ungültig ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_DayNumWeek($_sDate, $_bCalc=False) Local $iNum = __DateAsDayNumOfWeek($_sDate) $iNum = $_bCalc ? $iNum : ($iNum = 0 ? 7 : $iNum) Return $iNum EndFunc ;==>_Dt_DayNumWeek ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_DayNumYearToDate ; Description ...: Gibt n-ten Tag eines Jahres als Datum zurück ; Syntax ........: _Dt_DayNumYearToDate($_iYear, $_iDayNum) ; Parameters ....: $_iYear - Das Jahr 'YYYY' ; $_iDayNum - Nummer des Tages im Jahr ; Return values .: Success Das Datum an diesem Tag ; Failure 0 @error = 1 Tagesnummer ungültig ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_DayNumYearToDate($_iYear, $_iDayNum) Return __DayNumInYearToDate($_iYear, $_iDayNum) EndFunc ;==>_Dt_DayNumYearToDate ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_Diff ; Description ...: Gibt die Differenz zwischen zwei Datumswerten zurück. ; Syntax ........: _Dt_Diff($_sType, $_sDateStart, $_sDateEnd) ; Parameters ....: $_sType - Einheit für Differenz ('D'=Tag, 'M'=Monat, 'Y'=Jahr, 'w'=Woche) ; $_sDateStart - Datum Start 'YYYY/MM/DD'. ; $_sDateEnd - Datum Ende 'YYYY/MM/DD'. ; Return values .: Success Differenz der Einheit zwischen Start- u. Enddatum. Negativ, wenn Start > Ende. ; Failure 0 @error = 1 Datum Start/Ende ungültig ; @error = 2 Typ ungültig ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_Diff($_sType, $_sDateStart, $_sDateEnd) If Not StringInStr(' D M Y w ', ' ' & $_sType & ' ') Then Return SetError(2,0,0) Switch $_sType Case 'D' Return __DayDiff($_sDateStart, $_sDateEnd) Case 'M' Return __MonthDiff($_sDateStart, $_sDateEnd) Case 'Y' Return __YearDiff($_sDateStart, $_sDateEnd) Case 'w' Return __WeekDiff($_sDateStart, $_sDateEnd) EndSwitch EndFunc ;==>_Dt_Diff ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_Format ; Description ...: Gibt ein Datum formatiert zurück. ; Syntax ........: _Dt_Format($_sDate[, $_sLocale = 0]) ; Parameters ....: $_sDate - Datum 'YYYY/MM/DD'. ; $_sLocale - [optional] Der Formatierungsstring. Standard ist '0'=ShortLocale. Details s. Dateikopf "string format". ; Return values .: Success Das formatierte Datum. ; Failure 0 @error = 1 Datum ungültig ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_Format($_sDate, $_sLocale=0) Return __DateFormat($_sDate, $_sLocale) EndFunc ;==>_Dt_Format ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_IsLeapYear ; Description ...: Prüft gegebenes Jahr (od. Datum) auf Schaltjahr ; Syntax ........: _Dt_IsLeapYear($_vYear) ; Parameters ....: $_vYear - Jahr oder Datum 'YYYY/MM/DD' ; Return values .: Success True/False ; Failure 0 @error = 1 Datum ungültig ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_IsLeapYear($_vYear) ; akzeptiert Beides: Jahr als Integer (2018) - oder Datum als String ('2018/10/24[ hh:mm:ss]') If StringInStr($_vYear, '/') Then Local $aDate = __DateToArray($_vYear) If Not @error Then $_vYear = $aDate[0] Else Return SetError(1,0,0) EndIf EndIf Return __IsLeapYear($_vYear) EndFunc ;==>_Dt_IsLeapYear ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_IsValid ; Description ...: Prüft Datum '[YY]YY/MM/DD' auf Gültigkeit. Wenn gültig - Rückgabe Datumsstring als 'YYYY/MM/DD', sonst: 0 ; Syntax ........: _Dt_IsValid($_sDate) ; Parameters ....: $_sDate - Datum mit Jahr zwei-/vierstellig. Bei zweistellig wird Jahrhundert angepasst (TwoDigitYearMax). ; Return values .: gültig: Datum als 'YYYY/MM/DD' ; ungültig: 0 @error=1 ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_IsValid($_sDate) Return __IsValid($_sDate) EndFunc ;==>_Dt_IsValid ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_ShortLocaleToCalcDate ; Description ...: Gibt Datum des Formats ShortLocale als Rechen-Datum zurück ; Syntax ........: _Dt_ShortLocaleToCalcDate($_sDate) ; Parameters ....: $_sDate - Das Datum im Lokalen Kurzformat (DE = 'dd.MM.yyyy') ; Return values .: Success Das Datum als 'YYYY/MM/DD' ; Failure 0 @error = 1 Datum ungültig ; Author ........: BugFix ; Remarks .......: Das verwendete Kurzformat wird ausgelesen und dementsprechend werden die Werte für Tag, Monat, Jahr zugeordnet. ; =============================================================================================================================== Func _Dt_ShortLocaleToCalcDate($_sDate) Local $sDate = __ShortLocaleToCalcDate($_sDate) Return __IsValid($sDate) EndFunc ;==>_Dt_ShortLocaleToCalcDate ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_Today ; Description ...: Gibt das Datum für Heute zurück ; Syntax ........: _Dt_Today() ; Parameters ....: $_sLocale - [optional] Der Formatierungsstring. Standard ist ''=keine Formatierung. Details s. Dateikopf "string format". ; Return values .: Das Tagesdatum als 'YYYY/MM/DD' ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_Today($_sLocale='') Local $sResult = $SF('%s/%s/%s', @YEAR, @MON, @MDAY) Return ($_sLocale == '' ? $sResult : __DateFormat($sResult, $_sLocale)) EndFunc ;==>_Dt_Today ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_WeekNum ; Description ...: Gibt das Datum als Wochennummer zurück ; Syntax ........: _Dt_WeekNum($_sDate, $_bRetArray=False) ; Parameters ....: $_sDate - Datum 'YYYY/MM/DD' ; ...............: $_bRetArray - "True" gibt Array, "False" (Standard) gibt KW zurück ; Return values .: Success Nummer der Kalenderwoche oder Array [KW,Kalenderjahr_zur_KW] ; Failure 0 @error = 1 Datum ungültig ; Remarks .......: Der 29., 30. und 31. Dezember können schon zur KW1 des Folgejahres zählen. ; ...............: Der 1., 2. und 3. Januar können noch zur letzten KW des Vorjahres zählen. ; ...............: Der 4. Januar ist immer in Kalenderwoche 1. ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_WeekNum($_sDate, $_bRetArray=False) Return __DateGetWeekNum($_sDate, $_bRetArray) EndFunc ;==>_Dt_WeekNum ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Dt_YMDToCalcDate ; Description ...: Gibt die übergebenen Einzelwerte des Datums als Rechen-Datum zurück ; Syntax ........: _Dt_YMDToCalcDate($_iYear, $_iMonth, $_iDay) ; Parameters ....: $_iYear - Das Jahr [YY]YY (Jahrhundert für 19xx / 20xx optional) ; ...............: $_iMonth - Monat als Zahl ; ...............: $_iDay - Tag als Zahl ; Return values .: Success Das Datum als 'YYYY/MM/DD' ; Failure 0 @error = 1 Datum ungültig ; Author ........: BugFix ; =============================================================================================================================== Func _Dt_YMDToCalcDate($_iYear, $_iMonth, $_iDay) Local $sDate = __ParamDateToCalcDate($_iYear, $_iMonth, $_iDay) Return __IsValid($sDate) EndFunc ;==>_Dt_YMDToCalcDate ;=================================================================================================== #region - Internal ;--------------------------------------------------------------------------------------------------- Func __IsLeapYear($_iYear) Return (BitAnd($_iYear, 3) = 0) And (Mod($_iYear, 100) <> 0 Or Mod($_iYear, 400) = 0) EndFunc ;==>__IsLeapYear ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __DaysInYear($_iYear) Return (__IsLeapYear($_iYear) ? 366 : 365) EndFunc ;==>__DaysInYear ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __IsValid($_sDate) ; if true: returns formatted date (YYYY/MM/DD), else: 0 Local Static $aMonth[12] = [31,28,31,30,31,30,31,31,30,31,30,31] Local $aDate = __DateToArray($_sDate) If StringLen($aDate[0]) = 2 Then $aDate[0] = (Int(Int($aDate[0]) < $I2DIGITBORDER ? '20' & $aDate[0] : '19' & $aDate[0])) $aMonth[1] = __IsLeapYear($aDate[0]) ? 29 : 28 If ($aDate[1] < 1 Or $aDate[1] > 12) Or ($aDate[2] < 1 Or $aDate[2] > $aMonth[$aDate[1]-1]) Then Return SetError(1,0,0) Else Return $SF('%s/%02i/%02i', $aDate[0], $aDate[1], $aDate[2]) EndIf EndFunc ;==>__IsValid ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __DayArrayMonth($_iYear) Local Static $aMonth[12] = [31,28,31,30,31,30,31,31,30,31,30,31] $aMonth[1] = __IsLeapYear($_iYear) ? 29 : 28 Return $aMonth EndFunc ;==>__DayArrayMonth ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __DateToDayNumInYear($_sDate) ; 'YYYY/MM/DD' $_sDate = __IsValid($_sDate) If @error Then Return SetError(1,0,0) Local $aDate = __DateToArray($_sDate) $aDate[0] = Int($aDate[0]) $aDate[1] = Int($aDate[1]) $aDate[2] = Int($aDate[2]) Local $aMonth = __DayArrayMonth($aDate[0]) Local $iDayInYear = $aDate[2] If $aDate[1] = 1 Then Return $iDayInYear For $i = 1 To $aDate[1] -1 $iDayInYear += $aMonth[$i-1] Next Return $iDayInYear EndFunc ;==>__DateToDayNumInYear ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __DayNumInYearToDate($_iYear, $_iDayNum) Local Static $aDaySum[12] = [31,59,90,120,151,181,212,243,273,304,334,365] Local Static $aDaySumLeap[12] = [31,60,91,121,152,182,213,244,274,305,335,366] Local $aSum = __IsLeapYear($_iYear) ? $aDaySumLeap : $aDaySum If $_iDayNum < 1 Or $_iDayNum > $aSum[11] Then Return SetError(1,0,0) For $i = 0 To 11 If $_iDayNum <= $aSum[$i] Then If $i = 0 Then Return $SF('%s/01/%02i', $_iYear, $_iDayNum) Else Return $SF('%s/%02i/%02i', $_iYear, $i+1, $_iDayNum-$aSum[$i-1]) EndIf EndIf Next EndFunc ;==>__DayNumInYearToDate ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __DateAsDayNumOfWeek($_sDate) ; 0..6 = So..Sa $_sDate = __IsValid($_sDate) If @error Then Return SetError(1,0,0) ; Jan Feb Mrz Apr Mai Jun Jul Aug Sep Okt Nov Dez Local $aMonthOffset[12] = [ 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5] Local $aDate = __DateToArray($_sDate) Local $Y = $aDate[0], $M = $aDate[1], $D = $aDate[2] Local $WD = 0 Local $iDayNum = Mod($D, 7) Local $iMonthNum = $aMonthOffset[$M -1] Local $iYearNum = Mod(Mod($Y, 100) + Int(Mod($Y, 100)/ 4), 7) Local $iCenturyNum = (3 -(Mod(Int($Y/100), 4))) *2 If $M <= 2 And __IsLeapYear($Y) Then $iDayNum += 6 $WD = Mod(($iDayNum + $iMonthNum + $iYearNum + $iCenturyNum), 7) Return $WD EndFunc ;==>__DateAsDayNumOfWeek ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __DateAsDayNameOfWeek($_sDate, $_iType=0) ; $_iType: 0=short | 1=long, return: 1..7 = Mo..So $_sDate = __IsValid($_sDate) If @error Then Return SetError(1,0,0) Local $iDayNum = __DateAsDayNumOfWeek($_sDate) ; Ergebnis als: 0..6 $iDayNum = $iDayNum = 0 ? 7 : $iDayNum ; umwandeln zu 1..7 (Mo..So) Return __GetDayLocale($iDayNum, $_iType) EndFunc ;==>__DateAsDayNameOfWeek ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __DateGetWeekNum($_sDate, $_bRetArray=False) ; DIN 1355 : Der erste Donnerstag des Jahres ist immer in KW1. Eine Woche beginnt mit Montag. $_sDate = __IsValid($_sDate) If @error Then Return SetError(1,0,'ERROR') Local $aDate = __DateToArray($_sDate) Local $Y = $aDate[0] Local $aRet[2] = [0, Mod($Y, 100)] ; [0]=KW, [1]=zur KW zugehöriges Jahr (bei 1/52/53 muss das nicht das Jahr des Datums sein) Local $iDIY = __DateToDayNumInYear($_sDate) ; Wochentag des 1. Januar: Local $iWD1Jan = __DateAsDayNumOfWeek($SF('%s/%s/%s', $Y, 1, 1)) ; Sonderfall: Freitag und Samstag: If $iWD1Jan >= 5 Then $iWD1Jan -= 7 ; Sonderfall: "Das Jahr beginnt mit Wochennummer: - Nummer vom letzten Jahr": If ($iDIY + $iWD1Jan) <= 1 Then $aRet[0] = __DateGetWeekNum($SF('%s/%s/%s', $Y-1, 12, 31)) $aRet[1] = Mod($Y -1, 100) EndIf If $aRet[0] = 0 Then $aRet[0] = Int(($iDIY + $iWD1Jan + 5) / 7) ; 53 Wochen hat ein Jahr nur dann, wenn es mit einem Donnerstag beginnt (oder in einem Schaltjahr mit einem Mittwoch) ; In anderen Fällen ist diese Woche die KW1 des Folgejahres. Local $bLeapyear = __IsLeapYear($Y) If $aRet[0] = 53 Then If (($iWD1Jan = 4) Or _ ; Donnerstag ($iWD1Jan = -3) Or _ ; ebenfalls Do. (($iWD1Jan = 3) And $bLeapyear) Or _ ; Mittwoch im Schaltjahr (($iWD1Jan = -4) And $bLeapyear)) Then ; ebenfalls Mi. im Schaltjahr ; alles OK - keine Änderungen erforderlich Else ; Datum ist in KW1 des Folgejahres $aRet[0] = 1 $aRet[1] = Mod($Y +1, 100) EndIf EndIf EndIf Return ($_bRetArray ? $aRet : $aRet[0]) EndFunc ;==>__DateGetWeekNum ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __YearCountWeeks($_iYear) Local $iKW = 52 ; das Ergebnis von __DateAsDayNumOfWeek ist falsch für einen Sonntag, aber das hat keinen Einfluß auf diese Berechnung Local $iWD1stJan = __DateAsDayNumOfWeek($SF('%s/01/01', $_iYear)) ; Wochentag 01.01. des Jahres Local $iWDlastDec = __DateAsDayNumOfWeek($SF('%s/12/31', $_iYear)) ; Wochentag 31.12. des Jahres If __IsLeapYear($_iYear) Then ; im Schaltjahr If ($iWD1stJan = 3 And $iWDlastDec = 4) Or ($iWD1stJan = 4 And $iWDlastDec = 5) Then $iKW = 53 Else ; im Gemeinjahr If $iWD1stJan = 4 And $iWDlastDec = 4 Then $iKW = 53 EndIf Return $iKW EndFunc ;==>__YearCountWeeks ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __DateToArray($_sDate) ; yyyy/mm/dd[ hh:mm:ss[ tt]] Local $aRet = StringRegExp($_sDate, '^(\d{2,4}).(\d{1,2}).(\d{1,2})(?:\s(\d{2}):(\d{2}):(\d{2})\s?(AM|PM)?)?$', 1) Return (IsArray($aRet) ? $aRet : SetError(1)) EndFunc ;==>__DateToArray ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __DayDiff($_sDateStart, $_sDateEnd) $_sDateStart = __IsValid($_sDateStart) If @error Then Return SetError(1,0,0) $_sDateEnd = __IsValid($_sDateEnd) If @error Then Return SetError(1,0,0) Local $aStart = __DateToArray($_sDateStart) Local $aEnd = __DateToArray($_sDateEnd) ; im selben Jahr ? If $aStart[0] = $aEnd[0] Then Return __DateToDayNumInYear($_sDateEnd) - __DateToDayNumInYear($_sDateStart) EndIf Local $DIYstart = __DateToDayNumInYear($_sDateStart) Local $DIYend = __DateToDayNumInYear($_sDateEnd) Local $iDiff ; Diff Start- + Endjahr If $aStart[0] < $aEnd[0] Then $iDiff = (__DaysInYear($aStart[0]) - $DIYstart) + $DIYend Else $iDiff = (__DaysInYear($aEnd[0]) - $DIYend) + $DIYstart EndIf ; direkt aufeinanderfolgende Jahre: If $aStart[0] = $aEnd[0] -1 Or $aStart[0] = $aEnd[0] +1 Then Return ($aStart[0] < $aEnd[0] ? $iDiff : (-1 * $iDiff)) EndIf ; mehrjähriger Abstand: If $aStart[0] < $aEnd[0] Then ; Jahre zwischen Start- und Endjahr For $i = $aStart[0] +1 To $aEnd[0] -1 $iDiff += __DaysInYear($i) Next Else ; Jahre zwischen Start- und Endjahr For $i = $aEnd[0] +1 To $aStart[0] -1 $iDiff += __DaysInYear($i) Next $iDiff *= -1 EndIf Return $iDiff EndFunc ;==>__DayDiff ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __WeekDiff($_sDateStart, $_sDateEnd) $_sDateStart = __IsValid($_sDateStart) If @error Then Return SetError(1,0,0) $_sDateEnd = __IsValid($_sDateEnd) If @error Then Return SetError(1,0,0) Local $iDayDiff = __DayDiff($_sDateStart, $_sDateEnd) Return Int($iDayDiff/7) EndFunc ;==>__WeekDiff ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __MonthDiff($_sDateStart, $_sDateEnd) $_sDateStart = __IsValid($_sDateStart) If @error Then Return SetError(1,0,0) $_sDateEnd = __IsValid($_sDateEnd) If @error Then Return SetError(1,0,0) Local $aStart = __DateToArray($_sDateStart) Local $aEnd = __DateToArray($_sDateEnd) Local $iStart = StringReplace($_sDateStart, '/', '') Local $iEnd = StringReplace($_sDateEnd, '/', '') If $iStart = $iEnd Then Return 0 If StringLeft($iStart, 6) = StringLeft($iEnd, 6) Then Return 0 Local $iCorrectMon = $aEnd[2] < $aStart[2] ? 1 : 0 Local $iDiff If $iStart > $iEnd Then ; Start ist neuer als Ende If $aStart[0] = $aEnd[0] Then ; im selben Jahr ? Return -1*($aStart[1] - $aEnd[1]) -$iCorrectMon Else ; verschiedene Jahre $iDiff = $aStart[1] ; angefangene Monate im Startjahr While $aStart[0] <> $aEnd[0] $iDiff += 12 $aStart[0] -= 1 WEnd $iDiff -= 12 $iDiff += (12 - $aEnd[1]) Return -1*$iDiff -$iCorrectMon EndIf Else ; Start ist älter als Ende If $aStart[0] = $aEnd[0] Then ; im selben Jahr ? Return ($aEnd[1] - $aStart[1]) -$iCorrectMon Else ; verschiedene Jahre $iDiff = 12 - $aStart[1] ; Restmonate im Startjahr While $aStart[0] <> $aEnd[0] $iDiff += 12 $aStart[0] += 1 WEnd $iDiff -= 12 $iDiff += $aEnd[1] Return $iDiff -$iCorrectMon EndIf EndIf EndFunc ;==>__MonthDiff ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __YearDiff($_sDateStart, $_sDateEnd) $_sDateStart = __IsValid($_sDateStart) If @error Then Return SetError(1,0,0) $_sDateEnd = __IsValid($_sDateEnd) If @error Then Return SetError(1,0,0) Local $aStart = __DateToArray($_sDateStart) Local $aEnd = __DateToArray($_sDateEnd) Return $aStart[0] - $aEnd[0] EndFunc ;==>__YearDiff ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __DayAdd($_iCount, $_sDateStart) $_sDateStart = __IsValid($_sDateStart) If @error Then Return SetError(1,0,0) Local $aStart = __DateToArray($_sDateStart) Local $iDayTmp, $iYearTmp, $iDaysInYear If $_iCount = 0 Then Return $_sDateStart If $_iCount > 0 Then $iDayTmp = $_iCount + __DateToDayNumInYear($_sDateStart) If $iDayTmp <= __DaysInYear($aStart[0]) Then Return __DayNumInYearToDate($aStart[0], $iDayTmp) Else $iYearTmp = $aStart[0] $iDaysInYear = __DaysInYear($iYearTmp) While $iDayTmp > $iDaysInYear $iDayTmp -= $iDaysInYear $iYearTmp += 1 $iDaysInYear = __DaysInYear($iYearTmp) WEnd EndIf Return __DayNumInYearToDate($iYearTmp, $iDayTmp) Else ; subtrahieren $iDayTmp = __DateToDayNumInYear($_sDateStart) $_iCount = Abs($_iCount) If $_iCount < $iDayTmp Then ; Tag im aktuellen Jahr Return __DayNumInYearToDate($aStart[0], $iDayTmp - $_iCount) ElseIf $_iCount = $iDayTmp Then ; letzter Tag Vorjahr Return $SF('%i/12/31', $aStart[0] -1) ElseIf $_iCount > $iDayTmp Then ; Vorjahr oder älter $_iCount -= $iDayTmp ; Tage akt. Jahr abziehen $iYearTmp = $aStart[0] -1 ; Jahr = Vorjahr $iDaysInYear = __DaysInYear($iYearTmp) ; Anz. Tage in Vorjahr If $_iCount < $iDaysInYear Then ; Tag ist im Vorjahr Return __DayNumInYearToDate($iYearTmp, $iDaysInYear - $_iCount) ElseIf $_iCount = $iDaysInYear Then ; Tag ist letzter Tag Vorjahr -1 Return $SF('%i/12/31', $iYearTmp -1) ElseIf $_iCount > $iDaysInYear Then ; Tag ist älter als Vorjahr $_iCount -= $iDaysInYear $iYearTmp -= 1 $iDaysInYear = __DaysInYear($iYearTmp) While $_iCount >= $iDaysInYear $iYearTmp -= 1 $_iCount -= $iDaysInYear $iDaysInYear = __DaysInYear($iYearTmp) WEnd $iDayTmp = $iDaysInYear - $_iCount Return __DayNumInYearToDate($iYearTmp, $iDayTmp) EndIf EndIf EndIf EndFunc ;==>__DayAdd ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __WeekAdd($_iCount, $_sDateStart) $_sDateStart = __IsValid($_sDateStart) If @error Then Return SetError(1,0,0) Return __DayAdd($_iCount*7, $_sDateStart) EndFunc ;==>__WeekAdd ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __MonthAdd($_iCount, $_sDateStart) $_sDateStart = __IsValid($_sDateStart) If @error Then Return SetError(1,0,0) Local $aStart = __DateToArray($_sDateStart) Local $aMonth = __DayArrayMonth($aStart[0]) Local $iDayTmp = $aStart[2], $iMonthTmp, $iYearTmp If $_iCount = 0 Then Return $_sDateStart If $_iCount > 0 Then $iMonthTmp = $_iCount + $aStart[1] If $iMonthTmp <= 12 Then Return $SF('%i/%02i/%02i', $aStart[0], $iMonthTmp, ($iDayTmp > $aMonth[$iMonthTmp-1] ? $aMonth[$iMonthTmp-1] : $iDayTmp)) Else $iYearTmp = $aStart[0] While $iMonthTmp > 12 $iMonthTmp -= 12 $iYearTmp += 1 WEnd $aMonth = __DayArrayMonth($iYearTmp) EndIf Return $SF('%i/%02i/%02i', $iYearTmp, $iMonthTmp, ($iDayTmp > $aMonth[$iMonthTmp-1] ? $aMonth[$iMonthTmp-1] : $iDayTmp)) Else $_iCount = Abs($_iCount) If $_iCount < $aStart[1] Then $iMonthTmp = $aStart[1] - $_iCount Return $SF('%i/%02i/%02i', $aStart[0], $iMonthTmp, ($iDayTmp > $aMonth[$iMonthTmp-1] ? $aMonth[$iMonthTmp-1] : $iDayTmp)) ElseIf $_iCount = $aStart[1] Then Return $SF('%i/12/%02i', $aStart[0] -1, $iDayTmp) ElseIf $_iCount > $aStart[1] Then $iYearTmp = $aStart[0] -1 $_iCount -= $aStart[1] While $_iCount >= 12 $iYearTmp -= 1 $_iCount -= 12 WEnd $iMonthTmp = 12 - $_iCount $aMonth = __DayArrayMonth($iYearTmp) Return $SF('%i/%02i/%02i', $iYearTmp, $iMonthTmp, ($iDayTmp > $aMonth[$iMonthTmp-1] ? $aMonth[$iMonthTmp-1] : $iDayTmp)) EndIf EndIf EndFunc ;==>__MonthAdd ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __YearAdd($_iCount, $_sDateStart) $_sDateStart = __IsValid($_sDateStart) If @error Then Return SetError(1,0,0) Local $aStart = __DateToArray($_sDateStart) Local $iDayTmp = $aStart[2], $iYearTmp = $aStart[0] + $_iCount Local $aMonth = __DayArrayMonth($iYearTmp) Return $SF('%i/%02i/%02i', $iYearTmp, $aStart[1], ($iDayTmp > $aMonth[$aStart[1]-1] ? $aMonth[$aStart[1]-1] : $iDayTmp)) EndFunc ;==>__YearAdd ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __GetLocaleInfo($_LCType) Local $ret, $LCID, $sBuffer, $iLen Local $hDll = DllOpen("kernel32.dll") Local $ret = DllCall($hDll, 'long', 'GetSystemDefaultLCID') $LCID = $ret[0] $ret = DllCall($hDll, 'long', 'GetLocaleInfo', 'long', $LCID, 'long', $_LCType, 'str', $sBuffer, 'long', 0) $iLen = $ret[0] $ret = DllCall($hDll, 'long', 'GetLocaleInfo', 'long', $LCID, 'long', $_LCType, 'str', $sBuffer, 'long', $iLen) DllClose($hDll) Return $ret[3] EndFunc ;==>__GetLocaleInfo ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __GetDayLocale($_iWeekDay, $_iShort=0) ; $_iWeekDay: 1..7 Monday=1 | $_iShort: 0=short/ 1=long/ 2=shortest Local $aDayNameLong[8] = [0, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30] Local $aDayNameShort[8] = [0, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37] Local $aDayNameShortest[8] = [0, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66] Switch $_iShort Case 0 Return __GetLocaleInfo($aDayNameShort[$_iWeekDay]) Case 1 Return __GetLocaleInfo($aDayNameLong[$_iWeekDay]) Case 2 Return __GetLocaleInfo($aDayNameShortest[$_iWeekDay]) EndSwitch EndFunc ;==>__GetDayLocale ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __GetMonthLocale($_iMonth, $_iShort=0) ; 1..12 Januar=1 | long(def)/short=0/1 Local Static $aMonthNameLong[13] = [0, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43] Local Static $aMonthNameShort[13] = [0, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F] Switch $_iShort Case 0 Return __GetLocaleInfo($aMonthNameLong[$_iMonth]) Case 1 Return __GetLocaleInfo($aMonthNameShort[$_iMonth]) EndSwitch EndFunc ;==>__GetMonthLocale ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __DateFormat($_sDate, $_sLocale=0) $_sDate = __IsValid($_sDate) If @error Then Return SetError(1,0,0) Local $aDate = __DateToArray($_sDate) Switch String($_sLocale) Case '0' ; $LOCALE_SSHORTDATE (z.B. 'dd.MM.yyyy') $_sLocale = __GetLocaleInfo(0x1F) Case '1' ; $LOCALE_SLONGDATE (z.B. 'dddd, d. MMMM yyyy') $_sLocale = __GetLocaleInfo(0x20) Case Else ; benutzerdef. Formatstring (z.B. "'KW: 'w ddd, d.MMMM yy" ==> "KW: 3 Dienstag, 16. Januar 18" ; WochenNr ein/zweistellig ohne Vor-zeichen, Tag lang, Monat lang ; "'KW: 'ww dd, d.MMMM yy" ==> "KW: 03 Die, 16. Januar 18" ; WochenNr zweistellig mit Vor-Null, Tag kurz, Monat lang ; "'KW: 'sw dd, d.MMMM yy" ==> "KW: 3 Die, 16. Januar 18" ; WochenNr zweistellig mit Vor-Space, Tag kurz, Monat lang ; "'KW: 'w dd, d.MMM yy" ==> "KW: 3 Die, 16. Jan 18" ; WochenNr ein/zweistellig ohne Vor-zeichen, Tag kurz, Monat kurz ; "'KW: 'w dd, d.MM.yyyy" ==> "KW: 3 Die, 16.01.2018" ; WochenNr ein/zweistellig ohne Vor-zeichen, Tag kurz, Monat numerisch EndSwitch ; maskierte Stringbegrenzer ersetzen $_sLocale = StringReplace($_sLocale, '\"', Chr(1), 0, 1) $_sLocale = StringReplace($_sLocale, "\'", Chr(2), 0, 1) ; alle Formatbuchstabenfolgen jeweils einzelnem Zeichen zuweisen und damit ersetzen $_sLocale = StringReplace($_sLocale, 'dddd', Chr(3) , 0, 1) $_sLocale = StringReplace($_sLocale, 'ddd', Chr(4) , 0, 1) $_sLocale = StringReplace($_sLocale, 'dd', Chr(5) , 0, 1) $_sLocale = StringReplace($_sLocale, 'd', Chr(6) , 0, 1) $_sLocale = StringReplace($_sLocale, 'ww', Chr(7) , 0, 1) $_sLocale = StringReplace($_sLocale, 'sw', Chr(14), 0, 1) $_sLocale = StringReplace($_sLocale, 'w', Chr(15), 0, 1) $_sLocale = StringReplace($_sLocale, 'MMMM', Chr(16), 0, 1) $_sLocale = StringReplace($_sLocale, 'MMM', Chr(17), 0, 1) $_sLocale = StringReplace($_sLocale, 'MM', Chr(18), 0, 1) $_sLocale = StringReplace($_sLocale, 'M', Chr(19), 0, 1) $_sLocale = StringReplace($_sLocale, 'yyyy', Chr(20), 0, 1) $_sLocale = StringReplace($_sLocale, 'yy', Chr(21), 0, 1) $_sLocale = StringReplace($_sLocale, 'y', Chr(22), 0, 1) ; mgl. Literale separieren Local $sStrDelim = '', $aText If StringInStr($_sLocale, '"') Then $sStrDelim = '"' If StringInStr($_sLocale, "'") Then $sStrDelim = "'" If $sStrDelim <> '' Then $aText = StringRegExp($_sLocale, $SF('%s([^%s]+)%s', $sStrDelim, $sStrDelim, $sStrDelim), 3) ; Platzhalter mit Datumswerten ersetzen $_sLocale = StringReplace($_sLocale, Chr(3) , __DateAsDayNameOfWeek($_sDate, 1), 0, 1) $_sLocale = StringReplace($_sLocale, Chr(4) , __DateAsDayNameOfWeek($_sDate, 0), 0, 1) $_sLocale = StringReplace($_sLocale, Chr(5) , $SF('%02i', $aDate[2]), 0, 1) $_sLocale = StringReplace($_sLocale, Chr(6) , $SF('%i', $aDate[2]), 0, 1) $_sLocale = StringReplace($_sLocale, Chr(7) , $SF('%02i', __DateGetWeekNum($_sDate)), 0, 1) $_sLocale = StringReplace($_sLocale, Chr(14), $SF('% 2s', __DateGetWeekNum($_sDate)), 0, 1) $_sLocale = StringReplace($_sLocale, Chr(15), $SF('%i', __DateGetWeekNum($_sDate)), 0, 1) $_sLocale = StringReplace($_sLocale, Chr(16), __GetMonthLocale($aDate[1], 0), 0, 1) $_sLocale = StringReplace($_sLocale, Chr(17), __GetMonthLocale($aDate[1], 1), 0, 1) $_sLocale = StringReplace($_sLocale, Chr(18), $SF('%02i', $aDate[1]), 0, 1) $_sLocale = StringReplace($_sLocale, Chr(19), $SF('%i', $aDate[1]), 0, 1) $_sLocale = StringReplace($_sLocale, Chr(20), $aDate[0], 0, 1) $_sLocale = StringReplace($_sLocale, Chr(21), StringRight($aDate[0],2), 0, 1) $_sLocale = StringReplace($_sLocale, Chr(22), StringRight($aDate[0],1) , 0, 1) ; falls Literale vorhanden waren => wieder einsetzen, da eventuell Textzeichen mit Datumswerten ersetzt wurden If $sStrDelim <> '' Then For $i = 0 To UBound($aText) -1 $_sLocale = StringRegExpReplace($_sLocale, $SF('(%s[^%s]+%s)', $sStrDelim, $sStrDelim, $sStrDelim), $aText[$i], 1) Next EndIf ; Stringbegrenzer innnerhalb von Text wiederherstellen Return StringReplace(StringReplace($_sLocale, Chr(1), '"'), Chr(2), "'") EndFunc ;==>__DateFormat ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __ShortLocaleToCalcDate($_sDate) Local $sLocale = __GetLocaleInfo(0x1F) ; $LOCALE_SSHORTDATE Local $aLocale = StringRegExp($sLocale, '^(\w+).(\w+).(\w+)$', 1) Local $aDate = StringRegExp($_sDate, '^(\w+).(\w+).(\w+)', 1) Local $sD, $sM, $sY For $i = 0 To 2 If StringInStr($aLocale[$i], 'y') Then $sY = $aDate[$i] If StringLen($sY) = 2 Then $sY = Int(Int($sY) < $I2DIGITBORDER ? '20' & $sY : '19' & $sY) ElseIf StringInStr($aLocale[$i], 'M') Then $sM = $aDate[$i] ElseIf StringInStr($aLocale[$i], 'd') Then $sD = $aDate[$i] EndIf Next Return $SF('%s/%s/%s', $sY, $sM, $sD) EndFunc ;==>__ShortLocaleToCalcDate ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __ParamDateToCalcDate($_iYear, $_iMonth, $_iDay) If StringLen($_iYear) = 2 Then $_iYear = Int(Int($_iYear) < $I2DIGITBORDER ? '20' & $_iYear : '19' & $_iYear) Return $SF('%s/%s/%s', $_iYear, $_iMonth, $_iDay) EndFunc ;==>__ParamDateToCalcDate ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- Func __GetTwoDigitYearMax() Local $iYear = RegRead('HKEY_CURRENT_USER\Software\Policies\Microsoft\Control Panel\International\Calendars\TwoDigitYearMax', 1) ; default: 2029 Return ($iYear = '' ? 30 : StringRight($iYear, 2) +1) EndFunc ;==>__GetTwoDigitYearMax ;--------------------------------------------------------------------------------------------------- #endregion - Internal