Try Now
More in this section

Forums / Developing with Sitefinity / Request - Definitive Sitefinity DateTime

Request - Definitive Sitefinity DateTime

1 posts, 0 answered
  1. Mark
    Mark avatar
    147 posts
    01 Jun 2010
    14 Aug 2012
    Link to this post
    I have switched my code around too many times trying to save UTC times, ToLocal, ToSitefinityUITime ect. Can someone please chip in and let me know how I'm supposed to save a datetime from a RadDateTimePicker to sitefinity's eventStart/eventEnd fields?

    Here's my situation. I'm in the US Central Time Zone and have clients all over the US in different time zones. I set their time zone correctly in the Sitefinity settings. I have a front end event submission form.

    Default dates for RadDateTimePicker: 
    dtEventBegin.SelectedDate = DateTime.UtcNow.RoundQuarterHour();
                dtEventEnd.SelectedDate = DateTime.UtcNow.RoundQuarterHour().AddHours(1);
    Persisting the user adjusted dates:
    calEvent.EventStart = dtEventBegin.SelectedDate.Value;
                calEvent.EventEnd = dtEventEnd.SelectedDate.Value;
    Setting the edit page with the persisted values:
    DateTime startDT = calendarEvent.EventStart.ToSitefinityUITime();
                eventDetailCtl.dtEventBegin.SelectedDate = startDT;
                DateTime endDT = calendarEvent.EventEnd.HasValue ? calendarEvent.EventEnd.Value : calendarEvent.EventStart;
                eventDetailCtl.dtEventEnd.SelectedDate = endDT.ToSitefinityUITime();
    Display persisted dates on detail page:
    private string GetEventDate(Event calendarEvent)
                DateTime startDT = calendarEvent.EventStart;
                DateTime endDT = calendarEvent.EventEnd.HasValue ? calendarEvent.EventEnd.Value : calendarEvent.EventStart;
                StringBuilder date = new StringBuilder();
                date.AppendLine("<div>" + startDT.ToSitefinityUITime().ToString("dddd MMM d") + "</div>");
                if (calendarEvent.EventEnd.HasValue)
                    date.AppendLine("<div>" + startDT.ToSitefinityUITime().ToString("h:mm tt") + " to " + endDT.ToSitefinityUITime().ToString("h:mm tt") + "</div>");
                    date.AppendLine("<div>" + startDT.ToSitefinityUITime().ToString("h:mm tt") + "</div>");
                return date.ToString();

    I cannot for the life of me get this correct for every time zone. What am I doing wrong?
1 posts, 0 answered