-1

I retrieved the data from the database is include not only date but also time. I only want to dislay the time, like AM PM include, not include the date in the textbox in C# window form. For example, The textbox display the 09/08/2017 14:00:00 PM I want the textbox to display the 14:00:00 PM in C# window form.

Sam Myat
  • 1
  • 3
  • 1
    is the column type `Date` in you database table? – Mong Zhu Sep 14 '17 at 08:00
  • You can convert the string to a DateTime (if the date column in the database is Date then your result may not need converting) & then use a [Standard Format](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings) like T to convert the time to a string or a [Custom Format](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings) if it is not exactly as you want. – PaulF Sep 14 '17 at 08:11

3 Answers3

0

Hello you can simply use a split function like:

Try this :

var dates = "09/08/2017 14:00:00 PM ".split(" ");

You will get your required value: dates[1];

yasir_mughal
  • 112
  • 10
0

Try this:

 var Timeonly = DateTime.Parse("6/22/2009 10:00:00 AM");
 var time = Timeonly - Timeonly .Date;
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
  • "time" is a TimeSpan not the time of day & it will display as such - so no AM or PM which OP has said he wants. – PaulF Sep 14 '17 at 08:20
0

If you get DateTime object from data access layer then you can simply use ToLongTimeString() e.g. DateTime.Now.ToLongTimeString() and use current culture. If you want to specific culture then use ToString() with culture object provided like

DateTime.Now.ToString("T", new System.Globalization.CultureInfo("en-US"))
josip.k
  • 171
  • 2
  • 9