Recently some client of our DNN blog module requested a customized feature, he wanted to out the posted time of SunBlogNuke in a format that included the two letter suffix added to the day number, like "December 25th, 2009" as opposed to "December 25, 2009". After some investigation, it seems this is not supported out of the box (not surprising really). Finally I found the MarkGwilliam’s post (How To Append 'st', 'nd', 'rd' or 'th' To Day Numbers in Dates) which provided a ".NET Framework friendly" to implement this behavior and therefore offers good reuse value and is intuitive for .NET developers to use. I thought that is what we want and then extended it in our customized way which allows SunBlogNuke developers to consume the code more easily and flexible. Now I shared the VB.Net Function below and hope it helps if you also have the similar requirement:
Protected Function FormatPostedTimeWithDayNumberSuffix(Optional ByVal format As String = "MMMM d{0}, yyyy") As String Dim dateTime As DateTime = Date.Parse(Entry.PostedTime) If Not Null.IsNull(dateTime) Then Dim formatTime As String = dateTime.ToString(format) Dim day As Integer = dateTime.Day Dim dayFormat As String = String.Empty Select Case day Case 1, 21, 31 dayFormat = "st" Case 2, 22 dayFormat = "nd" Case 3, 23 dayFormat = "rd" Case Else dayFormat = "th" End Select Return String.Format(formatTime, dayFormat) End If Return Entry.PostedTime End Function
If you have more better or elegant solution appreciate your comments here. Thanks a lot.
Not sure I would include the "12" in the "nd" case ... as I would prefer 12th .. not 12nd Thanks for sharing
Hi Paul,I think so, too. That have been modified correctly. Thanks for your pointing out my fault. Welcome any more feeback or comments.Kind RegardsBaldwin
Great post, exactly what I was looking for. Seems silly really, that there isn't just a DD and DDD to go with the dd(1-31) and ddd(01-31) formats to append the suffix. Meh, oh well.
err... d and dd not dd and ddd.
Senior developer for dnn solution & founder of ultimate dnn blog module - SunBlogNuke, which is the best publishing tool for DotNetNuke (DNN) websites, with a focus on simplicity, ease of extensibility, web standards and usability. It includes a great suite of modules for blogging on your DNN site.
Re: DNN7 Blog Integrated with ModuleSearchBase
B- please FIX the bugs...driving me nuts!!!! Error: Edit blog entry is currently unavailable. DotNet...
-- kkuhns
Re: Fighting DNN Bugs Ⅱ: Why Can't Remove Google Analytics
Thanks a lot for your reference and it should be helpful for community guys. :)
-- Baldwin
please ensure you log any bugs to http://support.dnnsoftware.com - i searched and couldnt see this one...
-- Cathal
Re: Build DNN Rotator with GalleryPlus
How do you place the gallery within a blog entry. I saw in the below demo that a token was used ([SL...
-- Mary
Re: Enhance DNN Article Footers with Author Profiles
Please make sure that the bio field of this current host user is visual to public(you should find it...
I'm trying to get the bio to show up for a host user but it comes up blank. Can you replicate this issue...
-- Lucas
Re: [Kudos]DotNetNuke Blog Module In Depth Review
Yes, the latest package is absolutely compatible well with DNN7 and the performance was enhanced a lot...
Is it compatible with DNN 7
-- swayam
Re: SunBlogNuke 6.0 Technology Preview
No, actually the v6.0 had been available to downlaod for upgrade - http://www.sunblognuke.com/blog/entryid...
this article says that version 6.0 is not for production use. the article is from may 2013... is sun...
-- pekai
The opinions expressed here in are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2009 - 2024