Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following if statement. What I am trying to do is check inside xml document in objXMLInputDoc to see if the WarrantStatusDate inside NewWarrantStatus equals today's date, and if the WarrantStatusTime inside NewWarrantStatus is less than current time. If this is true, do nothing otherwise show error message by putting it inside variable strErrorResponse.

The time I have in objXMLInputDoc for WarrantStatusTime is 12:10:00.
If this if statement is executed at 12:15:00 (current time) this means do nothing because the WarrantStatusTime (12:10:00) is than the time of executing code.

If this if statement is executed at 12:00:00, then the error message should be put inside the strErrorResponse variable, because 12:00:00 (current time) is before WarrantStatusTime (12:10:00)

In my if statement I put < 4 which is minutes but am not sure if that's the way to check if WarrantStatusTime is less than current time.
How do I do this?

objXMLInputDoc has the following xml
XML
<?xml version="1.0" encoding="UTF-8"?>
<UpdateWarrantStatus>
	<WarrantNumber>
		<ID>2</ID>
	</WarrantNumber>
	<CurrentWarrantStatus>
		<WarrantStatusTypeText code="RECALLED">Recalled Inactive</WarrantStatusTypeText>
		<WarrantStatusDate>2018-10-16</WarrantStatusDate>
	</CurrentWarrantStatus>
	<NewWarrantStatus>
		<WarrantStatusTypeText code="IBARCLR">Warrant Cleared by Arrest</WarrantStatusTypeText>
		<WarrantStatusDate>2018-10-16</WarrantStatusDate>
		<WarrantStatusTime>12:10:00</WarrantStatusTime>
		<WarrantStatusComment>New status</WarrantStatusComment>
	</NewWarrantStatus>
</UpdateWarrantStatus>


What I have tried:

VB
'New warrant status date specified in e-file = today, and time is less < current time
dtmNewWarrantStatusDateTime = CDate(objXMLInputDoc.DocumentElement.SelectSingleNode("msc:NewWarrantStatus/msc:WarrantStatusDate").InnerText + " " + objXMLInputDoc.DocumentElement.SelectSingleNode("msc:NewWarrantStatus/msc:WarrantStatusTime").InnerText)
If ((dtmNewWarrantStatusDateTime.Date = Date.Today) And (DateDiff(DateInterval.Minute, Date.Now, dtmNewWarrantStatusDateTime) < 4)) Then
Else
    strErrorResponse = "New warrant status Date and Time combination is invalid because time is in the past. i.e time less than current time."
    objXMLInputDoc.DocumentElement.SetAttribute("error", strErrorResponse)
End If
Posted
Updated 18-Oct-18 8:12am
Comments
Alek Massey 16-Oct-18 17:13pm    
What is the problem you are having?
Member 11403304 17-Oct-18 9:18am    
The problem I am having is that, I get the error message even when I should not get one. I think the problem is where I am saying < 4. I am not sure how to make my if statement compare the time in the WarrantStatusTime element with current time (now) and if that time in WarrantStatusTime element is less than current time (e.g a few minutes earlier than current time) then do nothing. If that time in WarrantStatusTime is not earlier than current time, then show error message
I am doing two things.
1. Check if the date in NewWarrantStatus/WarrantStatusDate is equal to today's date. I have done that successfully.
2. Check the time in WarrantStatusDate/WarrantStatusTime and if this time is not less (earlier) than current time then show error message which means condition has failed. This is the part I need help with.
I knew it was not right but I needed to at least try something before seeking help.
All I need help with right now is part 2 of my if statement.
i.e. Check the time in WarrantStatusDate/WarrantStatusTime and if this time is not less (earlier) than current time, then I will add the error message. I know how to add the error message but need help to check WarrantStatusTime if it is not less than current time.
Thanks for your help.

1 solution

Replace
VB
If ((dtmNewWarrantStatusDateTime.Date = Date.Today) And (DateDiff(DateInterval.Minute, Date.Now, dtmNewWarrantStatusDateTime) < 4)) Then
Else
with
VB
If (Date.Now < dtmNewWarrantStatusDateTime) Then
Else

but preferably
VB
If (Date.Now > dtmNewWarrantStatusDateTime) Then
When you have an empty 'then' branch it is confusing when someone looks at your code.

If you are allowing a 4 minute window as it appears you are, subtract the dtmNewWarrantStatusDateTime from date.now and examine the timeinterval result's totalminutes property.
VB
if ((date.now - dtmNewWarrantStatusDateTime).TotalMinutes < 4) then
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900