By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,266 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,266 IT Pros & Developers. It's quick & easy.

Date and Time

P: n/a
Hi Guys

I have two DateTime pickers one shows the Date and the other the time, this
is a requirement of the solution. The problem I have is that when the time
is saved to the sql database into a datetime field it uses the default date
which is a problem when I try to sort, what I wanted to know is there a way
for me to set the date in the time picker to the date in the date picker?

Any help greatly appreciated.

Thanks
Mike

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I am going to assume that you HAVE to store the time into a datetime
field within SQL.

Before you save the values you can store the datetime value by taking
the date value of the date picker and putting the time value behind it.
Then you can through the time value into your db with the correct date
in front of it. This seems a tad askew though

hth

Nov 21 '05 #2

P: n/a
OK, if you can think of a better way the onyl requirement is that the date
is in one picker and the time is in another, please let me know I would be
more than interested, I am taking over someone elses project so I am just
trying to fix the problems so a different way would suit me fine.

Mike.

"Not Aaron" <aa**********@gmail.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
I am going to assume that you HAVE to store the time into a datetime
field within SQL.

Before you save the values you can store the datetime value by taking
the date value of the date picker and putting the time value behind it.
Then you can through the time value into your db with the correct date
in front of it. This seems a tad askew though

hth


Nov 21 '05 #3

P: n/a
MIchael,
You should be able to set the Value of your Time picker to the Date of the
Date picker & the Time of the Time picker, when the Date picker's value
changes.

Something like:

Private Sub pickerDate_ValueChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles pickerDate.ValueChanged
pickerTime.Value =
pickerDate.Value.Date.Add(pickerTime.Value.TimeOfD ay)
End Sub

Private Sub pickerTime_ValueChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles pickerTime.ValueChanged
Me.labelDateTime.Text = pickerTime.Value.ToString()
End Sub

Where pickerDate is a DateTimePicker for the Date value & pickerTime is a
DateTimePicker for the Time value.

I would consider encapsulating both controls into a new User Control to
allow easier reuse & better encapsulation...

Hope this helps
Jay

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:ut**************@TK2MSFTNGP10.phx.gbl...
Hi Guys

I have two DateTime pickers one shows the Date and the other the time,
this is a requirement of the solution. The problem I have is that when the
time is saved to the sql database into a datetime field it uses the
default date which is a problem when I try to sort, what I wanted to know
is there a way for me to set the date in the time picker to the date in
the date picker?

Any help greatly appreciated.

Thanks
Mike

Nov 21 '05 #4

P: n/a
Michael,
Do you have a single datetime field on the database or 2 datetime fields?

I would expect a single datetime field.

Using the code I posted earlier you can use 2 DateTimePickers, but store
both values in a single database field.

Hope this helps
Jay
"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
OK, if you can think of a better way the onyl requirement is that the date
is in one picker and the time is in another, please let me know I would be
more than interested, I am taking over someone elses project so I am just
trying to fix the problems so a different way would suit me fine.

Mike.

"Not Aaron" <aa**********@gmail.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
I am going to assume that you HAVE to store the time into a datetime
field within SQL.

Before you save the values you can store the datetime value by taking
the date value of the date picker and putting the time value behind it.
Then you can through the time value into your db with the correct date
in front of it. This seems a tad askew though

hth


Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.