Change Date Format into another format

Change DateTime.Now.ToString(“M/dd/yy hh:mm tt”) into DateTime.Now.ToString(“M/dd/yy”)

DateTime.parseExact(dateString1, "M/dd/yy hh:mm tt", nothing).toString("M/dd/yy")

Hi @Himanshu_Pratap_Rana
Try this
Convert.ToDateTime((“M/dd/yy hh:mm tt”).ToString).Date.ToString(“M/dd/yy”)

I hope it helps!!

Hi @Himanshu_Pratap_Rana

Try with this expression

DateTime.ParseExact(StringInput.ToString,"M/dd/yy hh:mm tt",System.Globalization.CultureInfo.InvariantCulture).ToString("M/dd/yy")

Regards
Gokul

Hi,

FYI, another approach:

If you have “M/dd/yy hh:mm tt” style string and need “M/dd/yy” style string, it’s ok to extract string before the first space, as the following.

yourDateString.Substring(0,yourDateString.IndexOf(" "))

OR

yourDateString.Split({" "c}).First()

Regards,

@Yoichi -if my string format comes in this “M/dd/yy hh:mm tt” format and the data table column value comes after 2 hours repeated(Ex-abc(same name) column time 6/30/23 12:30 PM and abc(same name) 6/30/23 2:30 PM column data come).I want latest data coming after 2:30 not previous. Can we handle this situation?

Hi,

In this case, we need to compare them as DateTime type.
If it’s datatable, the following may work.

dt.AsEnumerable.OrderByDescending(Function(r) CDate(r("columnname").ToString)).First().Item("columnname").ToString()

Regards,

1 Like

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