Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Time Issue Help/Suggestions?

Status
Not open for further replies.

Ddraig

MIS
Jul 16, 2004
97
US
Howdy,

I'm having an issue with my code and I can't seem to figure it out. I'm trying to make an alert system basically the program goes out to a site(rss feed) checks the time and if the alert is not older than 20 minutes (arbitrary number for coding purposes) then it displays a message (the feed details), But if it is older than 20 minutes then it doesn't display the alert.

So far I can not get the date time to compare the way I want it too. Let me post some of my code, it might be a bit of a mess since I've been going back and forth with it.

If Date.UtcNow.Subtract(System.TimeSpan.FromMinutes(20)) < xNode.selectSingleNode("pubDate").text Then
Messagebox.show("This is a new Alert Message")
Else
Messagebox.Show("No new Alerts")
End If

I am thinking it has something to do with the way my feed is putting in the Date Time and will need to hack the code a bit and fix the date time in it.


Perhaps there is a better way to do this? I'm not familiar with date.compare, but that might also be something useful.
 
Try this...

If DateTime.UtcNow.AddMinutes(-20) < DateTime.Parse(xNode.selectSingleNode("pubDate").text ) Then

Messagebox.show("This is a new Alert Message")
Else
Messagebox.Show("No new Alerts")
End If
 
Hmm nope that didn't seem to work. Anyway for me to reformat the date and time. Although I think I might have figured it out. :p

I was thinking reformating the date time actually into a date and I think that is what the issues is. It is trying to compare a string value with a datetime value. Not exactly sure on how to reformat the date and time that I pull in from the feed though.
 
Now that I noticed the datetime.parse guess that makes my last post pointless other than it didn't seem to work?
 
That text does seem to parse correctly. Here is a console application

Public Sub main()
Dim testTime As String = "Thu, 19 Jan 2006 15:32:43 GMT"
Console.WriteLine("UTC: " & DateTime.UtcNow.ToString)
Console.WriteLine("Parsed UTC: " & DateTime.Parse(testTime).ToUniversalTime.ToString)
If DateTime.UtcNow.Subtract(DateTime.Parse(testTime).ToUniversalTime()).Minutes > 20 Then
Console.WriteLine("Greater then 20 minutes")
Else
Console.WriteLine("Less then 20 minutes")
End If

End Sub
 
I'll give that a try in a few minutes have to go fix a blown PC hah.

Thanks for the help that looks like it might work right for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top