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!>??
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...
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)