mushin
Programmer
- Oct 4, 2000
- 49
Every time I think I understand datetime arithmetic, I prove myself wrong ......
I have 2 datetimepickers, one for date selection and 1 for
time selection.
My DB has 1 datetime field.
My user selects a date then a start time in the 2 DTP's
I want to combine the time portion from time dtp to the
date portion of the date dtp.
Code:
' dtwork vars are all datetime
dtWork = DTPstartTime.Value ' grab time portion of start time field
dtWork2 = DTPstart.Value ' set work var to apptdate
' now add time potion from start time to new dt
'================================================
dtWork2 = dtWork.AddHours(dtWork.Hour).AddMinutes(dtWork.Minute)
'==================================================
MessageBox.Show("Calc datetime", dtWork2.ToString)
This works, but doubles the time added. If I add 1 minute, the calc adds 2 and so on....
Is there a better way to do this ? Even If I get this to work right, seems like a lot of work for this.....
I have 2 datetimepickers, one for date selection and 1 for
time selection.
My DB has 1 datetime field.
My user selects a date then a start time in the 2 DTP's
I want to combine the time portion from time dtp to the
date portion of the date dtp.
Code:
' dtwork vars are all datetime
dtWork = DTPstartTime.Value ' grab time portion of start time field
dtWork2 = DTPstart.Value ' set work var to apptdate
' now add time potion from start time to new dt
'================================================
dtWork2 = dtWork.AddHours(dtWork.Hour).AddMinutes(dtWork.Minute)
'==================================================
MessageBox.Show("Calc datetime", dtWork2.ToString)
This works, but doubles the time added. If I add 1 minute, the calc adds 2 and so on....
Is there a better way to do this ? Even If I get this to work right, seems like a lot of work for this.....