Results 1 to 3 of 3

Thread: Setting a Specific Time on a Date variable?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    64

    Smile Setting a Specific Time on a Date variable?

    Hi All

    i have two date variables

    Dim dtDate as Date
    Dim dtTime as Date

    dtDate = "4/19/2007 15:00:00"
    dtTime = "1/1/1900 18:00:00"

    I want to set the time of dtTime on dtDate without changing the date
    so that

    Dim dtOutput as date

    dtOutPut = "4/19/2007 18:00:00"

    I know this is probably possible with string manipulation etc
    is there a more cleverer way of doing this using .net functions etc!>??

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Setting a Specific Time on a Date variable?

    What is the purpose of this, and what is dtTime for?

    Yes it's possible with string manipulation, but if you're looking for current time, then you need a different variable, such as:

    Dim dtDate As DateTime = System.DateTime.Now

    That will pull current date and dime into that variable...

    Details about the questions help a great detail in providing an answer...

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Setting a Specific Time on a Date variable?

    Hi, you can do something like this
    Code:
            Dim d As Date = #4/19/2007 12:00:00 PM#
            'Change the time from 12:00:00 PM to 3:30:20 PM
            d = d.Date.Add(TimeSpan.Parse("15:30:20"))
            MessageBox.Show(d.ToString)

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