Scrapping Text Date and Converting it to Date Variable

I’m attempting to scrap a date on a webpage that is in the following format: Apr 27, 2020 . I’ve been able to save the string to a variable but I need to convert it to a true date that I can perform math on it.

1 Like

Hi,

Please see this or any other forum posts.

If StrDate is the variable:

StrDate = StrDate.ToString("MMM dd, yyyy")

I’m not sure how to implement this code. This is the error I’m getting. Thank you for your help.

StockDateFormat should be a string. The only reason you should use a Datetime is if you’re going to perform operations on the datetime, such as comparing it with other datetimes, adding or subtracting days, etc. If you need this functionality as well, you’ll need another variable. You cannot format the date of a datetime, as it is an object for tracking dates and times agnostic of the locale.

Hi @zigmo
Check below

Hope this helps

Thanks

2 Likes

My goal is to get the String from the website and get it into a date format that I can do operations on it.

If you need to perform operations on the date, you will not need it in format ‘Apr 27, 2020’. The Datetime object stores the days, months, and year as modifiable objects. The way this appears on screen is something you use a String variable for.

As ksrinu070184 mentions above, you can convert the string to a Datetime using Convert.ToDateTime.

“If you need to perform operations on the date, you will not need it in format ‘Apr 27, 2020’.” - That is correct. That is the format from the website and I was attempting to convert it to a usable date format. I received a solution. Thank you for your time.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.