CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2006
    Posts
    6

    DateTime adding time

    Hello

    Ive got 2 strings in this format "01-01-2006 00:00:00" and "14:23:23". First is the date and second the time. I would like to put them into 1 DateTime.
    It seems obvious to parse them to DateTime and then add the time to the date using .AddHours etc.
    But the functions AddHours, AddMinutes and AddSeconds dont seem to work. Im putting the correct value in them but the time doestnt change.
    Anyone knows if these functions just dont work, or if im doing something wrong. I have no clue.

    thx

  2. #2
    Join Date
    Jun 2004
    Location
    New Jersey, USA
    Posts
    341

    Re: DateTime adding time

    Another thing you can is pars one as date , another as time , concatenate it and pars as datetime, something like this



    DateTime.Parse(datestring.ToShortDateString() + " " + timestring.ToShortTimeString());
    "We act as though comfort and luxury were the chief requirements of
    life, when all that we need to make us happy is something to be
    enthusiastic about."

    - Einstein

  3. #3
    Join Date
    Jul 2001
    Location
    Otaki, New Zealand
    Posts
    303

    Re: DateTime adding time

    I have used AddHours etc without any problems in my code so they do work.

    As always it is impossible to tell what you may be doing wrong unless you actually post your code.

    Regards
    Alan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured