You should also take a look to ensure that your input is in the correct format that is expected (if it is not, that will explain your "Input is not in the correct format error"). You mentioned that this occured when you were displaying lists, which
means that one or more of your Date fields may be in the incorrect format or possibly null.
I'm using the new Time data type for this column in Sql Server 2008; and the column is declared as Not Null; so, every value in this table should be correct. For some reason, DD does not like some acceptable string formats for this Time column. For example,
if I use this string suggested by Oned:
[DisplayFormat(DataFormatString:="{0:HH}")] (I'm of course using this in an attribute for the property as is documented for DD)
I get the same error as above:
Input string is not in a correct format.
If I use:
[DisplayFormat(DataFormatString:="{0:t}")]
I don't have an error *but* get this format instead: 09:35:00; however, I'm looking for something like this: 9:35 am.
Do you think there'd be an error somewhere when DD tries this Time data type in Sql Server 2008. I should say I'm using VS 2012 and the type Entity Framework shows for this column is Time.
manuelrivera
Member
6 Points
13 Posts
DataFormatString to display hours ...
Feb 25, 2013 10:07 PM|LINK
Hi all,
I was wondering how I can format values in a time property to show only hours. I've seen you can use format strings like this:
[DisplayFormat(DataFormatString = "{0:HH:mm:ss}")]
However, when I use this kind of strings, I have an error when I try to open "list" pages:
System.FormatException: Input string was not in a correct format.
Of course I can just use:
[DisplayFormat(DataFormatString = "{0:t}")]
It is just I want to have more options.
Thanks and bye ...
Rion William...
All-Star
27276 Points
4515 Posts
Re: DataFormatString to display hours ...
Feb 25, 2013 10:14 PM|LINK
You should take a look at the Custom Date and Time Formatting page on MSDN, which covers basically every type of formatting that you can perform to DateTime objects.
You should also take a look to ensure that your input is in the correct format that is expected (if it is not, that will explain your "Input is not in the correct format error"). You mentioned that this occured when you were displaying lists, which means that one or more of your Date fields may be in the incorrect format or possibly null.
oned_gk
All-Star
31511 Points
6431 Posts
Re: DataFormatString to display hours ...
Feb 25, 2013 10:15 PM|LINK
mr41971
Member
16 Points
78 Posts
Re: DataFormatString to display hours ...
Feb 25, 2013 10:43 PM|LINK
try {0:d}
farooque84
Participant
1358 Points
321 Posts
Re: DataFormatString to display hours ...
Feb 26, 2013 03:04 AM|LINK
Hi,
Try below URL
http://www.codeproject.com/Questions/261952/How-to-get-only-hours-from-a-date-in-asp-net
oned_gk
All-Star
31511 Points
6431 Posts
Re: DataFormatString to display hours ...
Feb 26, 2013 08:02 AM|LINK
Set directly to the control property
text='<%# Eval("yourfield","{0:HH}" %>'manuelrivera
Member
6 Points
13 Posts
Re: DataFormatString to display hours ...
Feb 26, 2013 01:10 PM|LINK
Hi, and many thanks for all your answers.
I'm using the new Time data type for this column in Sql Server 2008; and the column is declared as Not Null; so, every value in this table should be correct. For some reason, DD does not like some acceptable string formats for this Time column. For example, if I use this string suggested by Oned:
[DisplayFormat(DataFormatString:="{0:HH}")] (I'm of course using this in an attribute for the property as is documented for DD)I get the same error as above:Input string is not in a correct format.If I use:[DisplayFormat(DataFormatString:="{0:t}")]I don't have an error *but* get this format instead: 09:35:00; however, I'm looking for something like this: 9:35 am.Do you think there'd be an error somewhere when DD tries this Time data type in Sql Server 2008. I should say I'm using VS 2012 and the type Entity Framework shows for this column is Time.Thanks again for your answers.