|
-
Apr 19th, 2009, 06:25 AM
#1
Thread Starter
Lively Member
[RESOLVED] how to get only time from datetime part
hi..i have a table where in date column i have datetime datatype..i want to get only time in textbox...but i m getting both date and time by this below code..help anyone...thanks
i m using vs 2005...sql 2005
Code:
Try
cn = New SqlConnection("server=localhost;database=attendance1;uid=sa;password=;")
cn.Open()
cmd = New SqlCommand("select * from shift where shift_name='" & ComboBox1.Text & "' ", cn)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(1)
End While
Catch
End Try
dr.Close()
cn.Close()
-
Apr 19th, 2009, 06:46 AM
#2
Re: how to get only time from datetime part
The DateTime structure has methods to return a string representation. To get the time only you can call ToLongTimeString or ToShortTimeString. You can also call ToString and specify any standard or custom format string you want to get the date and/or time in any format. MSDN provides all the information you need on date and time format string. As an example, ToString("t") is equivalent to ToShortTimeString() and ToString("T") is equivalent to ToLongTimeString().
-
Apr 19th, 2009, 06:55 AM
#3
Thread Starter
Lively Member
Re: how to get only time from datetime part
i got blank by doing that....nothing appeared..do you have any code?
-
Apr 19th, 2009, 07:43 AM
#4
Re: how to get only time from datetime part
 Originally Posted by anirai
do you have any code?
Do you? If you don't show us what you did then we can't tell you what you did wrong.
-
Apr 20th, 2009, 12:10 AM
#5
Thread Starter
Lively Member
Re: how to get only time from datetime part
i posted my code into the first reply above...
-
Apr 20th, 2009, 12:31 AM
#6
Re: how to get only time from datetime part
That was your original code. I've told you what you need to do to achieve your goal and you said that you tried it and it didn't work. You need to show us that new code that you tried so we can tell what's wrong with it. If you change your code then the original is useless to us.
-
Apr 20th, 2009, 02:07 AM
#7
Thread Starter
Lively Member
Re: how to get only time from datetime part
thanks for your help//at first i used tostring("t")..no result..then i used toshorttimestring then i got only time...wonderfull....
Code:
TextBox1.Text = dr(1).toshorttimestring
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|