Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    117
    Thanks
    4
    Thanked 2 Times in 2 Posts

    DataFormatString of date fields

    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.

  • #2
    Regular Coder
    Join Date
    Jan 2007
    Posts
    117
    Thanks
    4
    Thanked 2 Times in 2 Posts
    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?

  • #3
    Regular Coder
    Join Date
    May 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    did you try:
    DataFormatString="{0:d}"

  • #4
    Regular Coder
    Join Date
    Jan 2007
    Posts
    117
    Thanks
    4
    Thanked 2 Times in 2 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •