Totally weird date format in DataGrid

P

Paul

Hi,
Everything went fine getting a short date format out of SQL into my
DataGrid with this:


<%# DataBinder.Eval(Container.DataItem, "Created", "{0:d}")%>


Then I got too fancy in SQL and started doing a RTRIM(date) when I was
retrieving the data. That screwed the pooch big time. Suddenly I lost
the date formatting and never suspected the dumb RTRIM. After removing
the RTRIM it started working again.

WHA??

I don't even have a clue. How can trimming blank space (that probably
didn't exist anyway) have any effect?


~Paul
 
A

alec maclean

Paul,
Try changing your formatting on your datagrid's date column to something
like:

{0:dd/MM/yyyy} (- this provides 24/10/2004 UK date format). You can
switch the MM and dd, etc, around as you wish.

If you have unwanted timestamp values appearing after the date, the above
formatting example will stop them appearing. The date from a SQL server
datetime column should not need trimming - you are using a datetime column
and not a varchar column?

Hope that helps.
 
P

Paul

Sharon, that would be a problem (converting a date to VARCHAR!)

Wow, the things I don't know already. :-D

~Paul
 
P

Paul

Thanks for the formatting tip, Alec. Yes, I was RTRIM-ing a date column
and that was converting it, I guess, to a VARCHAR. Not exactly what my
DataGrid was expecting, eh?


~Paul
 

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,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top