search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Resource start time format in scheduler

Asked by William Clark
4 years ago.

In the DB out times are formatted as 24 hours, but the start and stop times in the resource header is 12 hours. How do I change that. See image attached.

Comment posted by William Clark
4 years ago.

Perhaps I should restate this for clarity:

We would like the row headers to list times using a 24-hour clock (1300 instead of 1 PM for example) our data reflects that convention but the display on the row headers (start and stop times) do not. How do I set the time format for resource columns? The Gantt chart displays time using a 12-hour clock as well, would like them as 24-Hour also.

Answer posted by Dan Letecky [DayPilot]
4 years ago.

When you specify the data source for the Gantt columns it will take the source data and display them using the default format. In case of DateTime fields, it is DateTime.ToString() method. This method uses the default culture to format the date.

There are two options:

1. You can change the current culture of the thread. This can get you the 24-hour format but you still won't have much control over the actual string.

2. You can customize the column data using OnBeforeTaskRender:

protected override void OnBeforeTaskRender(BeforeTaskRenderArgs e)
{
    e.Row.Columns[3].Html = e.Start.ToString();  // customize the HTML
    e.Row.Columns[4].Html = e.End.ToString();  // customize the HTML
}
Comment posted by William Clark
4 years ago.

Works good for Gantt but not Scheduler.

Comment posted by William Clark
4 years ago.

There appears to not be a onBeforeResRender or anything that relates to before a resource row draws. I am unfamiliar enough with changing the culture that it seems a bit like using an axe instead of a pen knife and what else it may impact is a concern.

Looked at another way, the only reason I'm using the Scheduler is that it seemed harder to get a custom column for status in a Gantt (see new attachment). So the other way around the problem seems to go through the Gantt and custom columns.

Comment posted by William Clark
4 years ago.

Looks like I cannot add more images but it follows the same concept as your hotel room scheduler tutorial.

Comment posted by Dan Letecky [DayPilot]
4 years ago.

In the Scheduler, there are two ways to set the column HTML:

1. You can use Columns property of the Resource object (when loading the resources). This is what you are probably using now:

Resource r = new Resource("Resource 1", "1");   // the default column (column 0)
r.Columns.Add(new ResourceColumn("Column 1"));  // additional column #1 
r.Columns.Add(new ResourceColumn("Column 2"));  // additional column #1
Resources.Add(r);

2. You can also modify the HTML using OnBeforeResHeaderRender:

protected override void OnBeforeResHeaderRender(BeforeResHeaderRenderArgs e)
{
  e.Html = "Resource 1";
  e.Columns[0].Html = "Column 1";
  e.Columns[1].Html = "Column 2";
}

In both cases, you can use DateTime.ToString(format) to provide custom date/time format.

Example:

DateTime start = ...;  
DateTime end = ...;

Resource r = new Resource("Resource 1", "1");   // the default column (column 0)
r.Columns.Add(new ResourceColumn(start.ToString("MM/dd/yyyy H:mm:ss")));  // additional column #1 
r.Columns.Add(new ResourceColumn(end.ToString("MM/dd/yyyy H:mm:ss")));  // additional column #2
Resources.Add(r);

For the list of the format pattern elements please see: https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

Use "H"/"HH" for 24-hour format.
Use "h"/"hh" for 12-hour format.

Comment posted by William Clark
4 years ago.

Yes, the string format is the easy part. Employing that to the control is where I was stuck. I could set the columns to 00:00:00, I just couldn't find a way to convert the data in the columns (there is no e.End and e.Start only displays the time as 00:00:00).

I had tried the resource area yesterday as well to no avail but this morning I realized that start and stop had been converted to strings before the resource assignments, so I changed them to DateTime and was able to use the proper format. Thanks for confirming that I was on the right track.

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.