search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Date and Time

Asked by Dragan
12 years ago.

In my table Event i have eventstart and eventend in this format (2012-09-18 12:30:00.000), now i like to have eventdatestart (2012-09-18) in one column and eventtimestart (12:30:00.000) in other column. I will make this in my table Event, but I'm not sure that i will can display events? Can i make this, and to display the event in the calendar ? What change i need to made in my code, can you help me?

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DayPilotCalendar1.StartDate = DayPilot.Utils.Week.FirstDayOfWeek(new DateTime(2012, 09, 17));
DayPilotCalendar1.DataSource = dbGetEvents(DayPilotCalendar1.StartDate, DayPilotCalendar1.Days);
DataBind();
}

}

protected DataTable dbGetEvents(DateTime start, int days)
{

SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=Korisnik;Integrated Security=True";
SqlDataAdapter da = new SqlDataAdapter("SELECT e.id, e.name, e.eventstart, e.eventend, p.ime FROM Event e INNER JOIN RegistracijaKorisnik p ON e.PersonID = p.id WHERE NOT ((e.eventend <= @start) OR (e.eventstart >= @end ))", con);
da.SelectCommand.Parameters.AddWithValue("start", start);
da.SelectCommand.Parameters.AddWithValue("end", start.AddDays(days));
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}

private static DateTime firstDayOfWeek(DateTime day, DayOfWeek weekStarts)
{
DateTime d = day;
while (d.DayOfWeek != weekStarts)
{
d = d.AddDays(-1);
}

return d;
}

protected void DayPilotCalendar1_BeforeEventRender(object sender, DayPilot.Web.Ui.Events.Calendar.BeforeEventRenderEventArgs e)
{
// string color = e.DataItem["color"] as string;
//if (!String.IsNullOrEmpty(color))
// {
// e.DurationBarColor = color;
// }
e.InnerHTML += "From: " + e.DataItem["ime"] as string;
}

}

}

Answer posted by Dan Letecky [DayPilot]
12 years ago.

You will need to join these two fields in the select command:

http://stackoverflow.com/questions/700619/how-to-combine-date-from-one-field-with-time-from-another-field-ms-sql-server

But I would recommend doing the opposite: Store the start date and time as a single field and extract the date or time when needed:

http://stackoverflow.com/questions/113045/how-to-return-the-date-part-only-from-a-sql-server-datetime-datatype

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.