PDA

Click to See Complete Forum and Search --> : How do you format dates using a DataGrid?


mbaker
Sep 11th, 2002, 04:54 PM
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

Grimfort
Sep 12th, 2002, 10:59 AM
Try entering this with and without the quotes, I havent tried ot but it should work (me hopes :))

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

mbaker
Sep 12th, 2002, 04:08 PM
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

Grimfort
Sep 12th, 2002, 06:02 PM
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 :).

wheels
Oct 17th, 2002, 02:54 PM
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)