Opened 15 years ago

Closed 15 years ago

#465 closed Bug (Fixed)

_DateTimeSplit() results cause erroneous calc results when "Seconds" is missing

Reported by: cbruce Owned by: Gary
Milestone: Component: Standard UDFs
Version: Severity: None
Keywords: Date DateTimeSplit Cc:


I believe that the _DateTimeSplit() function is behaving incorrectly.

AutoIT allows us to use DateTime values that do NOT include "Seconds" in our calculations. But if you use such DateTime values in _DateAdd(), you get erroneous results.


$x = _DateAdd( 'h', 1, "2008/01/01 01:00")

Results in a value of "2008/01/01 01:59" instead of "2008/01/01 02:00".

The problem lies in the _DateTimeSplit() function, which is inserting "-1" into Time fields when there is missing input.

I believe the correct behavior should be to insert "0" into the Time fields in this condition.

Func _DateTimeSplit($sDate, ByRef $asDatePart, ByRef $iTimePart)
	Local $sDateTime
	Local $x
	; split the Date and Time portion
	$sDateTime = StringSplit($sDate, " T")
	; split the date portion
	If $sDateTime[0] > 0 Then $asDatePart = StringSplit($sDateTime[1], "/-.")
	; split the Time portion
	If $sDateTime[0] > 1 Then
		$iTimePart = StringSplit($sDateTime[2], ":")
		If UBound($iTimePart) < 4 Then ReDim $iTimePart[4]
		Dim $iTimePart[4]
	; Ensure the arrays contain 4 values
	If UBound($asDatePart) < 4 Then ReDim $asDatePart[4]
	; update the array to contain numbers not strings
	For $x = 1 To 3
		If StringIsInt($asDatePart[$x]) Then
			$asDatePart[$x] = Number($asDatePart[$x])
			$asDatePart[$x] = -1
		If StringIsInt($iTimePart[$x]) Then
			$iTimePart[$x] = Number($iTimePart[$x])
;	=============  PROBLEM  =================
			$iTimePart[$x] = -1
;	=============  PROBLEM  =================
;	=============  CHANGE  =================
			$iTimePart[$x] = 0
;	=============  CHANGE  =================
	Return (1)
EndFunc   ;==>_DateTimeSplit

Attachments (0)

Change History (3)

comment:1 Changed 15 years ago by Gary

  • Resolution set to No Bug
  • Status changed from new to closed

The help file doesn't state the seconds are optional

"Input date in the format YYYY/MM/DD[ HH:MM:SS]"

Either put in all the time or no time.

Now if Jos wishes to make the seconds optional then it would need to be changed.

As it stands now it is not a bug.

comment:2 Changed 15 years ago by Gary

  • Resolution No Bug deleted
  • Status changed from closed to reopened

Shoot looked at the add function not the split function, so yes it is a bug and it'll be fixed.

comment:3 Changed 15 years ago by Gary

  • Milestone set to
  • Resolution set to Fixed
  • Status changed from reopened to closed

Fixed in version:

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The owner will remain Gary.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.