Results 1 to 5 of 5

Thread: How do you format dates using a DataGrid?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    New Zealand
    Posts
    20

    Unhappy How do you format dates using a DataGrid?

    Hi,

    I've just starting using vb.net and i am trying to format a datetime value in my datagrid to display just the date. I am binding my grid at runtime. But have set up all the columns at design time. They are all bound columns. In the properties of the bound column there is one called 'Data Formating Expression' which when i looked it up in the Help it told me it was good for formatting dates etc but no examples!!!

    Has anyone used this property before or knows how to use it??? Or another way of formating dates??

    Thanks for your help.
    Michelle

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    Try entering this with and without the quotes, I havent tried ot but it should work (me hopes )

    "dd/MM/yyyy HH:mm:ss"

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    New Zealand
    Posts
    20
    Thanks, i thought it should be something like that too, but it writes over my dates with dd/MM/yyyy... so that it displays in the grid rather than a formatted date.

    I think (not sure) that it is expecting some kindof formula thingy in {} with a letter or something to tell its a date then a colon then the formula or something???? I found something similar to taht for numbers but it didn't work either so really not sure...

    Thanks for your help
    Michelle

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    Yer, there is a format like this

    {t: "dd/mm/yyyy"} but its only normally used as a timestamp for files, but give it a go .

  5. #5
    New Member
    Join Date
    Nov 2001
    Posts
    13
    note: this is for a label inside of a template column of a datagrid, but should point you in the right direction..

    Text='<%# FormatDateTime(DataBinder.Eval(Container, "DataItem.Date_to_be_formatted"), DateFormat.ShortDate) %>'

    perhaps something like this will work?

    FormatDateTime(var-date, DateFormat.ShortDate)

Posting Permissions

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



Click Here to Expand Forum to Full Width