Question

I have a datetimepicker with custom format hh:mm:ss tt

I want to fetch the data from mysql with time data type using MySqlDataReader

The date is fine using

dtpmyDate.Value = reader.GetDateTime("dateposted").ToShortDateString

How about the time?

this one resolve me

getTime = reader.GetString(reader.GetOrdinal("timeposted")).ToString
Dim today As DateTime = DateTime.Now.Date
Dim timeToSet As New TimeSpan(20, 20, 30)
dtpmyTime.Value = today + " " + getTime

dtpmyTime is datetimepicker with custom format is hh:mm:ss with ShowUpDown = true

I only wants the time value since the date will be updating current date to the database when the record is saved..

Thank you everyone. this site is more practicable place to query my problem that will solve immediately.

Was it helpful?

Solution

When you assign the .Value of a DateTimePicker, you need to include the date part as well as the time part. If the MySQL column has a type of TIME, then you should read that as a TimeSpan and add it to an appropriate date.

Dim today As DateTime = DateTime.Now.Date
Dim timeToSet As New TimeSpan(20, 20, 30)
DateTimePicker1.Value = today + timeToSet
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top