#include-once #include ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DateDiffAsApproxString ; Description ...: Returns a date diff in a human-readable format. Example: "2 months and 18 days" ; Syntax ........: _DateDiffAsApproxString($sDateOld, $sDateNew) ; Parameters ....: $sDateOld - The older date to diff. ; $sDateNew - The newer date to diff. ; Return values .: Success - Returns a string of approximate date difference. ; Failure - Returns an empty string an sets @error to 1. ; Author ........: orbs ; Modified ......: ; Remarks .......: The returned string is composed of only the first two most significant elements of difference. ; Both parameters should be specified in the standard AutoIt date format: "YYYY/MM/DD[ HH:MM:SS]" ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _DateDiffAsApproxString($sDateOld, $sDateNew) Local $aResult[2][2] Local $iResult = 0 Local $nTemp = 0 Local $aElement[6][2] = [['Y', 'year'],['M', 'month'],['D', 'day'],['h', 'hour'],['n', 'minute'],['s', 'second']] Local $iElement = 0 For $iElement = 0 To 5 If $iResult > 1 Then ExitLoop $nTemp = _DateDiff($aElement[$iElement][0], $sDateOld, $sDateNew) Select Case $nTemp <= 0 ContinueLoop Case $nTemp = 1 $aResult[$iResult][0] = 'a' If $iElement=3 Then $aResult[$iResult][0]&='n' $aResult[$iResult][1] = $aElement[$iElement][1] Case Else $aResult[$iResult][0] = $nTemp $aResult[$iResult][1] = $aElement[$iElement][1] & 's' EndSelect $iResult += 1 $sDateOld = _DateAdd($aElement[$iElement][0], $nTemp, $sDateOld) Next Switch $iResult Case 1 Return $aResult[0][0] & ' ' & $aResult[0][1] Case 2 Return $aResult[0][0] & ' ' & $aResult[0][1] & ' and ' & $aResult[1][0] & ' ' & $aResult[1][1] Case Else Return SetError(1, 0, '') EndSwitch EndFunc ;==>_DateDiffAsApproxString