Is there a way to show an editor for date and an editor for time?
I'm trying to bind a datetime field to an Infragistics Date Time editor and have a Windows Date and Time Properties interface.
Hi,
WebDateTimeEditor supports any format related to date/time. You may use standard dotnet formats like "d", "t", "g", etc. or explicit formats like "HH:mm:ss", "dd/MM/yyyy", etc.
However, WebDateTimeEditor is not able to provide "pure time" like TimeSpan, but only time-portion of date. Which means that end user will see only time-fields, but application will see all fields of DateTime. If date fields are missing, then fields of current date are used. So, if you need to get time portion, then you may substract Today date from date entered by user. Codes below show 3 editors: first shows to end user only date, second-time, third-date and time (all in current culture).
<ig:WebDateTimeEditor ID="WebDateTimeEditor1" runat="server"></ig:WebDateTimeEditor> <ig:WebDateTimeEditor ID="WebDateTimeEditor2" runat="server" EditModeFormat="t"></ig:WebDateTimeEditor> <ig:WebDateTimeEditor ID="WebDateTimeEditor3" runat="server" EditModeFormat="g"></ig:WebDateTimeEditor> <asp:Label ID="Label1" runat="server"></asp:Label> <asp:Button ID="Button1" runat="server" Text="Button" />
protected void Page_Load(object sender, EventArgs e){ this.Label1.Text = "<br />" + this.WebDateTimeEditor1.Date + "<br />" + this.WebDateTimeEditor2.Date + "<br />" + this.WebDateTimeEditor3.Date;}
I need to collect date and time using webdatetimeeditor in one control and need to use 24 hour time format. the EditModeFormat ="g" uses 12 hour format and user needs to select AM and PM. How to make this control to be accepte date time like 12/31/2013 23:34? Thanks
Hi Haijun,
When one-letter-flag is used for date format, then format is defined by culture of control or application (current thread). In order to set specific custom format, which does not depend on culture, application should set XxxFormat properties to explicit fields. That was mentioned in first response. Please consult DateTimeFormatInfo class for available flags. Particularly. in order to set 24-hour format, you will need to use "H" flag instead of "h".
The DisplayModeFormat is optional, can be used if application wants different appearance of text in edit/not-edit modes.
Example for 24-hours:<ig:WebDatePicker ID="WebDatePicker1" DisplayModeFormat="MMM, d yyyy HH:mm:ss" EditModeFormat="MM/dd/yyyy HH:mm:ss" runat="server"></ig:WebDatePicker>