-1

Hello Friends,

I need help to get the time value from MSSQL database to VB.Net Datetimepicker

I have a datetimepicker but the custom format is set to HH:mm tt so that I can get eg 11:20 AM

this value I have stored in database with the help of Label4.Text = DateTimePicker3.Value.ToShortTimeString

but now if I want to get the same value from database to datetimepicker what shud be done???

please do help me on this

Thanks in advance

4
Contributors
10
Replies
23
Views
4 Years
Discussion Span
Last Post by poojavb
0

Fetch the DateTime column value from the database, Cast it to DateTime type and assign this value to the DateTimePicker1.Value property.

Something like this:

IF reader.Read() Then
   DateTimePicker1.Value=reader.GetDateTime(0) 
End IF
0

I am getting an error 'Specified cast not valid'

If the database value is retrieved in a label or variable then how can I get the label or variable value to datetimepicker

Edited by poojavb

0

One thing I almost always have to do when working with dates from SQL server, is do a string split on the data coming in, seperating the date and the time.

Dim tmp As String = dt.Rows(0).Item(0)
Dim tmpAr() As String = tmp.Split(" ")
'tmpAr(0) will be the Date'
'tmpAr(1) will be the Time'

Edited by Begginnerdev: edit

0

Date is not stored in the database only the time value is stored because while storing the value in database I am using

DateTimePicker3.Value.ToShortTimeString

so only time value like 1:23 AM is getting stored in the database....

and I want to retrive the same value in datetimepicker....is it possible???

else is there any other way....I have set the datetimepicker custom format to HH:mm tt

0

i think first you have to set then format of your datetime picker so that it can only show the time then just simple bind it with your datasource.

Regards

0

Yes I have set the datatimepicker format to custom and the custom format as HH:mm tt....the value is getting correctly stored in database...but difficult to retrieve....can u please explain in detail....

0

If your data column type is a Date/Time, both the DATE and the time will be stored.....

Or are you just storing the value in a varchar?

0

Since I dont want date first i tried with the Time datatype in mssql and then later with varchar...but both did not work out....

0

No I just want time...

from datetimepicker1 i have time and in ms sql also time....but I am not able to get the data from database to picker...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.