How do I compare WarrantStatusTime with current time?
I have the if statement that I need help with.
What I am trying to do is check inside xml document in objXMLInputDoc to see if the NewWarrantStatus/WarrantStatusTime is less than current time.
In my if statement I put < 4 which is I think should be 4 minutes... but am not sure if that's correct.
How do I do this?
objXMLInputDoc has the following xml
Code:
<?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-17</WarrantStatusDate>
<WarrantStatusTime>12:10:00</WarrantStatusTime>
<WarrantStatusComment>New status</WarrantStatusComment>
</NewWarrantStatus>
</UpdateWarrantStatus>
What I have tried
Code:
dtmNewWarrantStatusDateTime = CDate(objXMLInputDoc.DocumentElement.SelectSingleNode("msc:NewWarrantStatus/msc:WarrantStatusDate", objXMLNameSpaceManager).InnerText + " " + objXMLInputDoc.DocumentElement.SelectSingleNode("msc:NewWarrantStatus/msc:WarrantStatusTime", objXMLNameSpaceManager).InnerText)
'I am using < 4 thinking this can be 4 minutes earlier than current time but it is not working
If ((dtmNewWarrantStatusDateTime.Date = Date.Today) And (DateDiff(DateInterval.Minute, Date.Now, dtmNewWarrantStatusDateTime) < 1)) Then
Else
strErrorResponse = "A Warrant Status Date and Time combination is invalid because time is in the future. i.e more than 4 minutes."
objXMLInputDoc.DocumentElement.SetAttribute("error", strErrorResponse)
End If
Re: How do I compare WarrantStatusTime with current time?
It isn't clear which way the 4 minutes should apply, but I think this (perhaps with the .AddMinutes moved to DateTime.Now) does what you want:
Code:
If ((dtmNewWarrantStatusDateTime.AddMinutes(4) < Date.Now) Then
Re: How do I compare WarrantStatusTime with current time?
The < 4 was just me trying to see what would happen. I do not need to add any minutes.
What I need is to just check if the dtmNewWarrantStatusDateTime is less than current time i.e Date.Now
Re: How do I compare WarrantStatusTime with current time?
In that case the simple version should be fine:
Code:
If (dtmNewWarrantStatusDateTime < Date.Now) Then
However, as you have no code before the Else, it would be better to invert the comparison (change < to >= ) and remove the Else, ie:
Code:
If (dtmNewWarrantStatusDateTime >= Date.Now) Then
strErrorResponse = ...