CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2000
    Location
    KSA
    Posts
    43

    Combine Date and Time in one variable

    Hi,

    I have two Date variables, the first
    one contains a Date, and the other one
    contains a Time.

    I want to combine them into one variable
    that will hold the date from the first
    variable, and the time from the
    second variable.

    I managed to do so by converting them to
    strings then assigning the resulting string
    into the third variable.. as in the
    following example:


    Dim da1 as date, ti1 as date, cmb as date

    da1 = #9/2/2001#
    ti1 = #6:30:00 PM#
    cmb = da1 & " " & ti1
    MsgBox cmb






    the problem with that code is that it does
    not interpret dates very well... for example
    where '9' in da1 is considered december,
    it is understood by cmb as day 9 of Feb!
    and if I reversed it .. it still give
    a wrong meaning..

    however when I tested the code in my home
    computer.. it works well with the same
    values with no problems (both computers
    running Windows 2000 Pro)..

    I think that there must be a better
    way to do it..
    if you have any Idea or thought .. please help!

    Thanks in advance





  2. #2
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Re: Combine Date and Time in one variable

    Why you do not add them, just like:
    da3=da1 + ti1.
    You'll have correct result in da3 variable. Then display it as you want.
    Vlad



  3. #3
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: Combine Date and Time in one variable

    Hi,
    It seems that your two computers are using different system locale.
    The system locale can be changed from Control Panel. Double-click the Regional Settings icon, and then change the system locale value (and then restart your computer).






    Regards,

    Michi

  4. #4
    Join Date
    Jun 2000
    Location
    KSA
    Posts
    43

    Re: Combine Date and Time in one variable

    Thanks Michi...
    both computers have the same locale! and I was looking for a locale-independant method.

    the solution was as vchapran said.. just add them!

    Thanks for your reply.


  5. #5
    Join Date
    Jun 2000
    Location
    KSA
    Posts
    43

    Re: Combine Date and Time in one variable

    Thanks vchapran,
    You were right.. how could I miss that! I've tried 'da1 & da2' but I didn't think of 'da1 + da2' !

    Thanks again and Regards.


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