Convert "October 04 at 3:00pm" to DateTime variable

I am creating this topic again because the last solution is not working.

I added the following code to convert:
Datetime.ParseExact(Split(timePostedSTR.tostring," “)(0).tostring+” “+Split(timePostedSTR.tostring,” “)(1).tostring+” "+now.tostring(“yyyy”),“MMMM dd yyyy”,system.globalization.cultureinfo.invariantculture)

However I am now getting this error:

I believe it is because of ‘yyyy’, while the input does not give a year.

So my question is how can I modify this so it works without the year as well?

1 Like

May I know what is the value of timePostedSTR
Without year it would be like this

Datetime.ParseExact(Split(timePostedSTR.tostring," “)(0).tostring+” “+Split(timePostedSTR.tostring,” “)(1).tostring,“MMMM dd”,system.globalization.cultureinfo.invariantculture)

But that won’t be an issue
We need to validate the input once
Then we could surely resolve this


1 Like


Probably, you should set the 2nd argument of ParseExact method to “MMMM d yyyy” instead of "MMMM dd yyyy" because your log shows the input string is not “October 04” but “October 4”.



This variable is the input. I am scraping it from the web.
an example of timePostedSTR would be “October 04 at 3:00pm”

Makes sense I Will try both ways

1 Like

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