Totally weird date format in DataGrid

  • Thread starter Thread starter Paul
  • Start date Start date
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
 
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.
 
Sharon, that would be a problem (converting a date to VARCHAR!)

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

~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
 
Back
Top