I have a date value in my database, which (unfortunately) is converted into datetime by the entity model (since it apparently doesn't support just date data types) which is then displayed in my dynamic data application with a full date time value - bleck!
I want to cut off the time portion and just display the date. Any suggestions on how this can be accomplished?
Member
4 Points
106 Posts
Trim DateTime Value for Display
Jan 26, 2011 11:26 AM|davidshq|LINK
I have a date value in my database, which (unfortunately) is converted into datetime by the entity model (since it apparently doesn't support just date data types) which is then displayed in my dynamic data application with a full date time value - bleck! I want to cut off the time portion and just display the date. Any suggestions on how this can be accomplished?
Thanks,
Dave
Member
711 Points
249 Posts
Re: Trim DateTime Value for Display
Jan 26, 2011 11:59 AM|sbrauen|LINK
Does using the .ToShortDateString() function work?
Member
20 Points
5 Posts
Re: Trim DateTime Value for Display
Jan 26, 2011 12:04 PM|wava|LINK
You can use the Standard DateTime format strings to format the data.
http://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.71).aspx
If one of those in not exactly what you want you can use Custom DateTime format strings
http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.71).aspx
If you are using databound controls like a datagrid you add the DataFormatString attribute
<asp:BoundField DataField="createDate" HeaderText="Open"
DataFormatString="{0:d}" ... />
All-Star
17916 Points
5681 Posts
MVP
Re: Trim DateTime Value for Display
Jan 26, 2011 03:15 PM|sjnaughton|LINK
In your metadata add [DataType(DataType.Data)] to the field you want to display as Date.
Dynamic Data 4
Always seeking an elegant solution.
Member
221 Points
112 Posts
Re: Trim DateTime Value for Display
Jan 27, 2011 01:43 AM|vaibhav_shah1988|LINK
you can use .ToShortDateString() method if you want to show date as "27-01-2011"...
& you can use .ToLongDateString() method if you want to show date as "27 January 2011"....
Click Here For More Answers
Member
452 Points
234 Posts
Re: Trim DateTime Value for Display
Jan 27, 2011 01:49 AM|Yasser Shaikh|LINK
using
objectDateTime.ToLongDateTime() would give you an output like "01 January 2011", while using
objectDateTime.ToShortDateTime() would give you an output like "01-01-2011", so its upto you to decide which format you need.
Hope this helps, cheers! :)
Member
4 Points
106 Posts
Re: Trim DateTime Value for Display
Jan 28, 2011 11:13 AM|davidshq|LINK
Thanks folks! I used the suggestion from sjnaughton and it works beautifully. :)
Dave