Convert date time format

excel

#1

Dear all,

I have value cell below:

image

when get and show it. The value is “11/23/2017 0:00”.
Now, i want to convert it to format “MMdd”.
I tried use CDate(DateTime_v).ToString(“MMdd”) or DateTime.ParseExact(BuyDate_v.ToString, “MMdd”, enUS, DateTimeStyles.None).
But it is not correct. Please help to check.

Thank you.


#2

@AKY try this Convert.ToDateTime(ur variable name).ToString(“MMdd”)


#3

Hi @Manjuts90,

I tried by this way and i have the result below.
1/27/1903 0:00
Not the right time i need.
Do you have another help?

Thank you


#4

Hi @AKY,

Try below code.

DateTime.ParseExact(BuyDate_v.ToString, "MM/dd/yyyy h:ss", System.Globalization.CultureInfo.InvariantCulture).ToString("MMdd")

Regards,
Arivu


#5

Hi @arivu96,

I tried with your help.
And have error below:

image

So i think value BuyDate_v.ToString when i got was not correct.
I message box again and the value right of BuyDate_v.ToString is “11/23/2017 00:00:00” .
So, how can i change “MM/dd/yyyy h:ss” to correct?


#6

Hi @AKY,

you told above format.

Try below Code.

DateTime.ParseExact(BuyDate_v.ToString, "MM/dd/yyyy hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture).ToString("MMdd")

Regards,
Arivu


#7

Hi @arivu96,

After convert, this is the result:

1/27/1903 12:00:00 AM.

I don’t know how it content “AM”.
Please help to check.

Thank you