DateTime.AddHours method doesn't add anything

R

radiolandog

I am getting a DateTime value from a Calendar Control. It returns the date
at midnight. I want to add some hours to the value before I display it in a
text box.

C# back end to a web form - here's the code
-------------------------------------------------------------------------------------
private DateTime startTime;

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
startTime = Calandar1.SelectedDate;
startTime.AddHours(8.5);
startDateTextBox.Text = startTime.ToString();
 
M

Mike Brind

radiolandog said:
I am getting a DateTime value from a Calendar Control. It returns the
date
at midnight. I want to add some hours to the value before I display it in
a
text box.

C# back end to a web form - here's the code:

You are working in Dotnet. This group covers classic asp. Dotnet is
totally different and has its own group:
microsoft.public.dotnet.framework.aspnet.
 
A

Anthony Jones

radiolandog said:
I am getting a DateTime value from a Calendar Control. It returns the date
at midnight. I want to add some hours to the value before I display it in a
text box.

C# back end to a web form - here's the code:
-------------------------------------------------------------------------- -----------
private DateTime startTime;

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
startTime = Calandar1.SelectedDate;
startTime.AddHours(8.5);
startDateTextBox.Text = startTime.ToString();
}
-------------------------------------------------------------------------- -----------

If I debug and step through the code, startTime gets set to the selected
data at 12:00:00 AM. The AddHours method does not change its value, it stays
at 12:00:00 AM.

microsoft.public.dotnet.framework.aspnet

Would be a better group to ask, this group is for Classic ASP.

However try:-

startTime = startTime.AddHours(8.5);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top