I have a date time variable which is scraped from the web (lets call it scrapedTime). Now I want to compare this variable to DateTime.Now and see how many days apart they are.
Something like:
DateTime.Now - scrapedTime = 5 days
I tried doing it like this^ already but I get an error: “Value of type system.timespan cannot be converted to date”. The thing is I am not even using a system.timespan variable
could someone please let me know how I can do this.
I am getting the error string was not recognized as a valid date time.
Let me go over what I have so far.
Scrape text from web. Note - It’s format is like so “September 25 at 9:18 PM”. All I care about is date, not time. I saved this string as timeSTR
Convert to date time variable, so for that I did used code: scrapedDate = Datetime.ParseExact(Split(timeSTR.tostring," “)(0).tostring+” “+Split(timeSTR.tostring,” “)(1).tostring+” "+now.tostring(“yyyy”),“MMMM dd yyyy”,system.globalization.cultureinfo.invariantculture)
Now when I try to add your code I did it like so (and added it as step 3): resultSTR = DateTime.ParseExact(timeSTR, “mm-dd-yyyy”, System.Globalization.DateTimeFormatInfo.InvariantInfo).ToString(“dd-mm-yyyy”)