Convert date of string format to date time

@Chris_Livesay What is the Date Format of another Date ?

I am going to be taking it and comparing it to Today’s date to find less than or equal to.

@Chris_Livesay You can do this inside an if :
Datetime.ParseExact(pdate.ToString,“yyyy-MM-dd”,System.Globalization.CultureInfo.InvariantCulture) <=Now.Date

Really, so no need for a conversion to a datetime variable?

@Chris_Livesay You are converting it :sweat_smile: , if you want to use the value for later purpose, then you’ll need to store it in a Date variable

OK I think I see what you are saying now. I will give this a go! Thank you very much.

1 Like

I have:

pdateNew=Datetime.ParseExact(pdate.ToString,“yyyy-MM-dd”,System.Globalization.CultureInfo.InvariantCulture)

Still doesn’t like it. I am trying to make pdateNew a date variable to pass along. Should I just abandon that and stick with the pdate string I am getting from the transaction item and the conversion you gave me?

@Chris_Livesay If you are using this Assign Statement, then your Date will be assigned to pDateNew variable, then you can use pDateNew <= Now.Date in if Condition, It is one and the same :sweat_smile: , Except that you’re Storing the Date Value

Right but it’s not liking that.
“Assign: String was not recognized as a valid DateTime.”

@Chris_Livesay Ohh, Then Maybe there’s Something Wrong with pDate, Can you show me the Value of pDate in a Message Box or WriteLine

image

@Chris_Livesay It Should have worked :sweat_smile:, It’s in the right Format
Have you checked this Statement Directly in a Message Box :

Datetime.ParseExact(pdate.ToString.trim,“yyyy-MM-dd”,System.Globalization.CultureInfo.InvariantCulture) <=Now.Date

Should I not have it set to this data type?

image

@Chris_Livesay If the type is System.DateTime it should be Proper, I just Checked again , it worked fine for me as well :sweat_smile: Can you use “2017-10-27” directly instead of pDate just to clarif

It’s adding the time
image

@Chris_LivesaySince you’re Comparing it with Now.Date, so i don’t think it will be a Problem, Or do you think it’s a problem :sweat_smile:

Suddenly it decided to like it. :roll_eyes: Thank you very much for your help, @supermanPunch

1 Like

Lol no I am wrong. It was working because I had that string in there “2017-10-27” so there must be something with pdate.

@Chris_Livesay Yes :sweat_smile: , Can you Write Line pDate again in this way:

pdate+“End”

@supermanPunch Found it. There is a damn space in the front of the string! I added the space into the conversion code string and it’s running. Spaces kill you every time!!