Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8855633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:10:48+00:00 2026-06-14T14:10:48+00:00

If the entry in my SQL table is 09:00:00 my cells either show up

  • 0

If the entry in my SQL table is 09:00:00 my cells either show up as something like 09:00:00 or if i throw in a string format like this:

    <DataGridTextColumn Binding="{Binding Path=tin, StringFormat=\{0:hh\\:mm\}}"  Header="Time In:"/>

I get 9:00. How do i make it formatted for a short time string like “09:00 AM”?

I have tried using StringFormat=t and it makes the cell blank. Any use of “t” and the cell goes blank. I am really in a pickle here.

The DataGrid is populated with a dataset named displayGrid. entryGrid is the DataGrid object.
entryGrid.ItemsSource = displayGrid.Tables[0].DefaultView;

What I am looking for here is what to throw in the XAML to format this correctly. I need to go from 09:00:00 in my SQL 2008 Table to 09:00 AM in my datagrid. I am using C#.Net and XAML in VS 2012. I am super new to coding so I am sure it is a simple mistake or syntax error. Thank you for any help you can give.

EDIT:

I have even gone back, tried autogenerating the columns with the following code to format the cell:

 private void ResultsDataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
        if (e.PropertyType == typeof(DateTime))
        {
            DataGridTextColumn dataGridTextColumn = e.Column as DataGridTextColumn;
            if (dataGridTextColumn.Header.ToString().Equals("wkdate"))
            {
                dataGridTextColumn.Binding.StringFormat = "{0:d}";
            }
            if(dataGridTextColumn.Header.ToString().Equals("tin"))
            {
                dataGridTextColumn.Binding.StringFormat = "{0:t}";

            }
        }
    }

works for the date but not the time! This is driving me bonkers. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:10:50+00:00Added an answer on June 14, 2026 at 2:10 pm

    As per your format, you could update your existing XAML Code and write as below:

    <DataGridTextColumn Binding="{Binding Path=tin, StringFormat=\{0:hh:mm tt\}}"  Header="Time In:"/>
    

    Hope this helps

    Alternatively, Could you could you the below. I am sure this is working as i have used it in many project.

    CS File Code:

     [ValueConversion(typeof(DateTime), typeof(string))]
        public class StringTime : IValueConverter
        {
            #region IValueConverter Members
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value == null || value.ToString() == "")
                {
                    return "";
                }
                String str = ((DateTime)value).ToString("hh:mm tt");
                return str;
            }
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value == null || value.ToString() == "")
                {
                    return value;
                }
                DateTime dtr = DateTime.MinValue.Date;
                dtr = dtr.AddYears(1899);
                if (value == null)
                    return dtr;
                dtr = dtr.AddHours(double.Parse((value.ToString().Substring(0, 2))));
                dtr = dtr.AddMinutes(double.Parse((value.ToString().Substring(3, 2))));
                if(value.ToString().Substring(7, 2) == "PM")
                    dtr = dtr.AddHours(12);
    
                return dtr;
            }
            #endregion
        }
    

    XAML File:

        <Page.Resources>
            <custom:StringTime x:Key="StringTime" />
        </Page.Resources>
    
    DataGrid Column Code:
    
        <DataGridTextColumn Binding="{Binding Path=tin, Converter={StaticResource StringTime}}"  Header="Time In:"/>
    

    Let me know if you have any issues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My input is an XML column in SQL Server table like this: <word Entry=Ketab
I have an SQL table that looks like this: CREATE TABLE diet_watch ( entry_date
I'd like to let my user add HTML to an entry in a SQL
I have an audit table in SQL server. It is to record an entry
When trying to create a table using clojure.java.sql/create-table I get the exception: batch entry
DB: SQL Server 2005 We have a table that has data in this manner:
I'm using linq-to-sql to update an entry in the table. I'm first fetching a
How are CLR (.NET) objects managed in SQL Server? The entry point to any
for (Entry<String, String> entry : map.entrySet()) { String delimiter = **; result = result.replace(delimiter
This entry appears to be about 80% of what I want to do but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.