DateTime.AddHours method doesn't add anything

Discussion in 'ASP General' started by radiolandog, Nov 23, 2006.

  1. radiolandog

    radiolandog Guest

    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.

    --
    Thanks!
    Marty
    radiolandog, Nov 23, 2006
    #1
    1. Advertising

  2. radiolandog

    Mike Brind Guest

    "radiolandog" <martykilroy at yahoo> wrote in message
    news:...
    >
    > 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.

    --
    Mike Brind
    Mike Brind, Nov 23, 2006
    #2
    1. Advertising

  3. "radiolandog" <martykilroy at yahoo> wrote in message
    news:...
    >
    > 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);


    >
    Anthony Jones, Nov 23, 2006
    #3
  4. radiolandog

    radiolandog Guest

    Got it!

    Thanks, Anthony Happy Thanksgiving.
    --

    Thanks!
    Marty





    "Anthony Jones" wrote:

    >
    > "radiolandog" <martykilroy at yahoo> wrote in message
    > news:...
    > >
    > > 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);
    >
    >
    > >

    >
    >
    >
    radiolandog, Nov 23, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    690
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    523
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    377
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    329
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    744
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page