Pregunta

I have a list of birthdays in Umbraco and want to order them by date day but by ordering by the date picker "birthday" I get a list of the youngest first rather than by day month year

so what i need is 1st may 1945, 2nd may 1933 etc

I am currently just using .OrderBy("Birthday")

¿Fue útil?

Solución

Try this.....

@inherits umbraco.MacroEngines.DynamicNodeContext
@using umbraco.NodeFactory

@{
    var currentMode = umbraco.NodeFactory.Node.GetCurrent();

    Nodes nodes = currentMode.Children;

    var dateList = new List<DateTime>();

    foreach (Node node in nodes)
    {
        DateTime date = Convert.ToDateTime(node.GetProperty("datePick").Value);

        dateList.Add(date);
    }

    dateList.Sort((a, b) => a.Day.CompareTo(b.Day));

    dateList.Sort((a, b) => a.Month.CompareTo(b.Month));  


    foreach (var date in dateList)
    {
        string Date = String.Format("{0: d MMM yyyy}", @date);

        <p>@Date</p>
    }   

 }    

Otros consejos

Would this not work?

.OrderBy("Birthday desc")

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top