Date time is dd/mm/yyyy 00:00:00 and other time is dd/mm/yyyy

I loop in a excel file, some times i have this date time format dd/mm/yyyy 00:00:00 and other time i have this format dd/mm/yyyy

How can i have every time this format : dd/mm/yyyy

Hi,

Can you try to surround it by double quote as the following?

Date_Piece.ToString("dd/MM/yyyy")

Regards,

@Soudios use “dd/MM/yyyy HH:mm:ss” in quote

Best regards,
Vrushali

Hey!

Try like this

Cdate(Date_Piece.ToShortDateString).ToString("dd-MM-yyyy")

This will give you the Desired format

Regards,
NaNi

I have this issue

I have an other issue here

doesnt work

Hi,

Is Date_Piece string type? If so, can you try the following?

If you need DateTime type, the following works.

dateTimeVar = DateTime.ParseExact(Date_Piece,{"dd/MM/yyyy", "dd/MM/yyyy HH:mm:ss"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None)

If you need string type, the following will work.

strDateTime = DateTime.ParseExact(Date_Piece,{"dd/MM/yyyy", "dd/MM/yyyy HH:mm:ss"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("dd/MM/yyyy")

@Yoichi

Not working with string

Hi,

Can you share content of Date_Piece using WriteLine or MessageBox?

Regards,

image ==> Its working
image ==> its not working
image

Hi,

In my environment, “03/06/2022 00:00:00” works good as the following.

As there might be extra whitespace in the string, can you try trim method as the following?

DateTime.ParseExact(Date_Piece.Trim(),{"dd/MM/yyyy", "dd/MM/yyyy HH:mm:ss"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("dd/MM/yyyy") 

Regards,

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