Date format

G

Guest

How to i bring the date in (dd/mm/yyyy) format from the database?

Here is what am doing... but having problem converting the string into the
short date (dd/mm/yyyy)

string strDateReturned =
((DbDataRecord)e.Item.DataItem)["DateReturned"].ToString();

many thanks
 
G

Guest

make sure the culture is set to a culture that views dates in the format you
wish. For EN-US, the standard is mm/dd/yyyy. To flip, you need to ensure the
culture is in a format that will yield dd/mm/yyyy before displaying the date.
That should solve your problem.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
G

Guest

Ok this works:
<%# String.Format("{0:d}",DataBinder.Eval(Container.DataItem,
"DateReceived"))%>

but if i try to do the same in code behind it does not work..

string strDateReturned =
((DbDataRecord)e.Item.DataItem)["DateReturned"].ToString();

String.Format("{0:d}",strDateReturned);

whats wrong?

Cowboy (Gregory A. Beamer) - MVP said:
make sure the culture is set to a culture that views dates in the format you
wish. For EN-US, the standard is mm/dd/yyyy. To flip, you need to ensure the
culture is in a format that will yield dd/mm/yyyy before displaying the date.
That should solve your problem.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

huzz said:
How to i bring the date in (dd/mm/yyyy) format from the database?

Here is what am doing... but having problem converting the string into the
short date (dd/mm/yyyy)

string strDateReturned =
((DbDataRecord)e.Item.DataItem)["DateReturned"].ToString();

many thanks
 
W

William F. Robertson, Jr.

This should work.

string dateReturned = ( ( DateTime )( (
DbDataRecord)e.Item.DataItem)["DateReturned"] ).ToString( "dd/MM/yyyy" );

You will need to cast it from a object to a DateTime, then you can call the
..ToString() method passing the formatter you want to use.

bill
 
G

Guest

Thanks bill, that what i needed :)

William F. Robertson said:
This should work.

string dateReturned = ( ( DateTime )( (
DbDataRecord)e.Item.DataItem)["DateReturned"] ).ToString( "dd/MM/yyyy" );

You will need to cast it from a object to a DateTime, then you can call the
..ToString() method passing the formatter you want to use.

bill

huzz said:
How to i bring the date in (dd/mm/yyyy) format from the database?

Here is what am doing... but having problem converting the string into the
short date (dd/mm/yyyy)

string strDateReturned =
((DbDataRecord)e.Item.DataItem)["DateReturned"].ToString();

many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top