how to save time into database when seleced from datetime picker
can someone plz tell me how to save time from datetimepicke in to database...i m using vb.net
Re: how to save time into database when seleced from datetime picker
You'll have a textbox. With the icon next to it which launches the datetimepicker. Datetimepicker writes into textbox. In the codebehind, you read what's in the textbox.
Re: how to save time into database when seleced from datetime picker
Quote:
Originally Posted by mendhak
You'll have a textbox. With the icon next to it which launches the datetimepicker. Datetimepicker writes into textbox. In the codebehind, you read what's in the textbox.
what icon that u meant? .. i cant find any icon next to text box .. :( ..
Re: how to save time into database when seleced from datetime picker
Use any image. People usually use a tiny icon of a calendar. Some even use a link. Look at this example
http://aspnet.4guysfromrolla.com/articles/030202-1.aspx
Re: how to save time into database when seleced from datetime picker
im worlin on window application.....n not on asp.net.....
Re: how to save time into database when seleced from datetime picker
This is the ASP.NET forum. I'll move your thread.
Re: how to save time into database when seleced from datetime picker
Do you have a datetimepicker on your form? if not, add one.
Code:
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
'add your code here
End Sub
Re: how to save time into database when seleced from datetime picker
The DateTime object contains both the date part and the time part. If you just want the time from the Value of your datetimepicker (wich is a datetime object), you would read the TimeOfDay property of that datetime object (which is a TimeSpan). However, you should save the value as datetime and use only the part that you need.
Re: how to save time into database when seleced from datetime picker
can u plz tell me how to retrive only time?im not getting it...plzzzzzzzz
Re: how to save time into database when seleced from datetime picker
Maybe I'm not normal but the extra "z"s don't make me want to help any more than I did. In fact, they make me kind of want to help a little less. They're kind of annoying.
Anyway, exactly what you should do depends on exactly how you want to use the value. If you want to use the value in code then you'd do as stanav already suggested and get a TimeSpan from the TimeOfDay property of your DateTime:
vb.net Code:
Dim myDate As Date 'get this value from database.
Dim myTime As TimeSpan = myDate.TimeOfDay
If you want to display the value to the user then you'd simply format the DateTime as a string:
vb.net Code:
Dim myDate As Date 'get this value from database.
Dim myTime As String = myDate.ToShortTimeString()
MessageBox.Show(myTime)
myTime = myDate.ToString("HH:mm")
MessageBox.Show(myTime)