...

View Full Version : DataFormatString of date fields



jleone
01-11-2007, 04:12 PM
OK, did lots of google searching on this and I keep coming up with the same thing. My problem is I'm trying to format a date field in my datagrid. I want to get rid of the time.

My dataformatstring is set to {0:mm/dd/yyyy} AND my HTMLEncode is set to FALSE (which is the supposed fix I find everywhere on the web). However, this is not working. Any suggestions from those who do have it working or know how else to make it work? Should I remove the column from the datagrid and re-add it back?

NOTE: I had no problems with formatting my "currency" fields on other datagrids on other pages in my project.

jleone
01-11-2007, 04:26 PM
OK, my bad, but still a problem. Turns out when I was building my datagrid -dt.Columns.Add("item_date", GetType(DateTime)) - I had changed my GetType from DateTime to String when I was trying to get it to work before I found the HTMLEncode property fix. I changed it back and it works fine now.

However, now that the time issue is solved, it is showing the wrong date. The date of the item is 01/10/2007, but it is showing 00/10/2007.

Any thoughts?

otaku149
01-11-2007, 04:38 PM
did you try:
DataFormatString="{0:d}"

jleone
01-11-2007, 04:40 PM
Well I did a little more research. Turns out I was using the "minutes" of the time in my format and not "months" of the date.

I was using this format: {0:mm/dd/yyyy}

It should be: {0:MM/dd/yyyy}

Lowercase "mm" is for minutes and uppercase "MM" is for months.

Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum