How to convert Date into DateTime type from String type

Hi, I have stored date in dd-MMM-yyyy but it’s in string type var, I want to store it into DateTime format. I need the same format.

Convert.ToDateTime(strDate).ToString(“dd-MMM-yyyy HH:mm:ss”)
Please try this one

2 Likes

@Jan_Brian_Despi No bro, if you see I need the same result in 3rd as I got in second. I don’t need time I need only date in same format. If you see in 2nd It’s in string type and in 3rd It’s in DateTime type format is changed.
image

2 Likes

Check whether this will work for you

Convert.ToDateTime(strDate).Date

2 Likes

No bro, It’s giving me the diff format see in the yellow highlighted color. I want the same format which is in the 2nd line
image

oh so you need the same format in the DateTime type… hmm… I don’t think that is possible. What I know is when we want to have a specific format, we have it as string…

Let me check…

Btw, may I know why exactly you need to have that format in the DateTime type? Does it make any difference?

2 Likes

Bro, if I use in a database query will it take???

Yes. I think it will take it

2 Likes

@balkishan DateTime is a Struct in System namespace. It does not have a format. You can represent it in many string formats.

1 Like

Yes… it will take it… no problem :slight_smile:
Until it is in the proper DateTime datatype format, it will work just fine in the databases too…

2 Likes

Hey

Here is a detailed article on that :slight_smile: