You must Sign In to post a response.

How to remove time from date getting data from data base and assign text box

How to remove time from date
getting data from data base and assign text box.

I want assign date to my text box but failed fill without time
how can i filter time
from my date field in date field in database
using data set.



Thanks,
Madhu


Comments

Author: Himanshu Patel20 Jul 2011 Member Level: Gold   Points : 2

You can use Split function with separator as ' ' space.

String[] result = date.ToString().Split(' ');

Textbox1.Text = result[0].ToString();

Author: Mahesh Nagar20 Jul 2011 Member Level: Gold   Points : 2

convert first date-time to date
then assign to text box
or you can fetch data from database like this


select convert(varchar(10) , dt_field_name ,103)
from table_name

Author: Pawan Awasthi20 Jul 2011 Member Level: Gold   Points : 2

Hi Madhu,

There are 3 ways to remove the time which is getting from the database.

1. While rereieving the date from the database, format the date in such a way so only the date part will come in the dataset and then you can assign it directly to the date textbox.

2. The other way is that with out touching the database, you just split the date with time from the space character and get the first part.

3. After getting the date with time as string, you can formt it at the fronend by converting it in to date and then convert it in to .toShortDate. it will get only the date without time.

Author: Manoranjan Sahoo20 Jul 2011 Member Level: Gold   Points : 2

you can use below code to get only date part :


SELECT CONVERT(VARCHAR(10),GETDATE(),105)


it will show following result :
20-07-2011

Author: Subhash.N20 Jul 2011 Member Level: Silver   Points : 2

Hi Madhu

can you can the Date to textbox


string dt=ds.Table[0].Row[0]["CreatedDate"].Tostring();
txtDate.Text=Convert.ToDateTime(dt).ToString("dd/MM/yyyy");


Or

In select Query


select convert(varchar, getdate(), 103)

Author: Madhus20 Jul 2011 Member Level: Silver   Points : 1

Thank you all
its working





Thaks,
Madhu.


Sign In to post your comments