Want to convert time from HH:MM:SS to HH:MM

In Above screenshot totalHours variable is Generic and timeDifference is also Generic.

timeDifference variable output i am getting as 00:00:00(HH:MM:SS) and i want that in 00:00(HH:MM).

I did this TimeSpan.Parse(timeDifference).ToString(“HH:mm”) but its throwing error.

Hi @Puneet_Singh1

Try this:
totalHours = TimeSpan.Parse(timeDifference).ToString("hh\:mm")

@Puneet_Singh1

string timeDifferenceString = “00:00:00”;

// Convert the string to a TimeSpan object.
TimeSpan timeDifference = TimeSpan.Parse(timeDifferenceString, DateTimeFormatInfo.InvariantCulture);

// Get the hours and minutes from the TimeSpan object.
int hours = timeDifference.Hours;
int minutes = timeDifference.Minutes;

// Format the hours and minutes as a string.
string formattedTimeDifference = string.Format(“{0}:{1}”, hours, minutes);

Hi @Puneet_Singh1

Try this

Regards,

Not Working. Totalhours are showing as 0.5 and when i am converting into minutes it showing 00:00

Try:

> timeDifference.ToString("hh\:mm")

Hi @Puneet_Singh1

Try this

DateTime.Now.ToString(“HH:mm”)

Hi @Puneet_Singh1

Try this

DateTime.ParseExact(dATRER,"HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture)

Regards,

@Puneet_Singh1

Try this also

DateTime.ParseExact(dATRER,"HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture).ToString("HH:mm")

I hope you understand!!

Hi @Puneet_Singh1

If you got the solution for your question. Please mark it as solution to close the thread.

Regards,

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