|
-
Dec 12th, 2007, 04:26 PM
#1
Thread Starter
Junior Member
Format Date
Hi all,
My question has to do with formatting a date returned in a datatable.
Currently the column displays like this "2/4/1958 12:00:00 AM", but i would like for it to display like this "02/04/1958" so that i can set it to the text property of a textbox on a form.
Thanks
p.s. the sql query looks like this select bd, name from table where lname='Doe'
the database it is querying is an oracle db, and the program is written in vs 2005.
-
Dec 12th, 2007, 04:36 PM
#2
Hyperactive Member
Re: Format Date
formattedDate = DateTime.Now.ToString("dd / MM / yyyy");
-
Dec 12th, 2007, 04:44 PM
#3
Thread Starter
Junior Member
Re: Format Date
wouldnt that format the current date? I'd like to format a date that looks like
"2/4/1958 12:00:00 AM"
I tried the following
DateTime bdate;
bdate = (DateTime) myRow[2];
textbox.text = bdate.ToShortDateString();
and it doesnt keep the 0 in front of months and days
i.e. 02/07/1954 comes out as 2/7/1954. is there a way to keep the leading 0's
Last edited by RiverX; Dec 12th, 2007 at 05:00 PM.
-
Dec 12th, 2007, 05:10 PM
#4
Thread Starter
Junior Member
Re: Format Date
Okay i figured it out
DateTime bdate;
bdate = (DateTime) myRow[2];
text.Text = bdate.ToString("MM/dd/yyyy");
is this the best way or is there another more efficient way?
Thanks
-
Dec 12th, 2007, 05:11 PM
#5
Hyperactive Member
Re: Format Date
Well i made a litte application that contains two textboxes, and a button. One of the textbox contained your desired date;
The button formats it to your desried format!
Code:
String t1 = (textBox1.Text);
DateTime datex = System.DateTime.Parse(t1);
String strDate = datex.ToString("dd /mm /yyyy");
textBox2.Text = strDate;
U can jst vary it from there
-
Dec 12th, 2007, 05:14 PM
#6
Hyperactive Member
Re: Format Date
if you just want it without the leading zero just do the following format:
d/m/yyyy
That should work i think
-
Dec 12th, 2007, 05:28 PM
#7
Thread Starter
Junior Member
Re: Format Date
yeah thank you. I got it. 
Is this the best way or is there a more efficient way as well?
Take care
-
Dec 12th, 2007, 05:33 PM
#8
Hyperactive Member
Re: Format Date
Im not sure whether that's the best way to be honest, that's the only way i can think of atm, haven't done C# in a while.
I guess it depends on the context of what you're doing..
Good luck
-
Jul 23rd, 2008, 01:42 AM
#9
Hyperactive Member
Re: Format Date
I tried this on a German machine, the formatting were wrong due to they use JJJJ and not YYYY for the year, and that gave me an error, and I wonder if some other country may be differ, the dd/mm/yyyy wont work already, is there another way?
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
|