Im creating a project where the a blog can be submitted, the date is stored in the database as dd/mm/yy, however im using LINQ to SQL to get the date as well as other information, the problem comes when i want to display the date in a particular layout (similar to this website: http://highrockmedia.com/tags/css).

below is the code im using to get the data but i want to split the date up into different labels so i can position them where i want. Is this the best option?

using (apiContentDataContext api_GetContent = new apiContentDataContext())
            {

                var result = from c in api_GetContent.getAllContent()                   

                             select new
                             {
                                 c.content_Date,
                                 c.content_Intro,                                
                                 c.content_Main,
                                 c.content_Title                   

                             };              
                
               
                LVContentHome.DataSource = result;
                LVContentHome.DataBind();

but now the date has been retrieved from the database i cannot do anything with it, if i try it result in an error.


The alternative way was to do the following:

<a><%# Eval("content_Date", "{0:dd}")%></a>
<a><%# Eval("content_Date", "{0:MM}")%></a>
<a><%# Eval("content_Date", "{0:yyyy}")%></a>

I don't know if there's a better way to do this? Any help/suggestions would be very helpful.

Regards
BarrieGrant1

split the parts in your Linq statement instead of accepting the date as a whole value:

select new {
    c.content_Date.Day,
    c.content_Date.Month,
    c.content_Date.Year,
    c.content_Intro,                                
    c.content_Main,
    c.content_Title                   
};

Thanks for your help, I have tried a number of ways to split the date as you suggested. Is it best to do this as an array or is there a split method that i can do within the stored procedure.

Regards
BarrieGrant1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.