How can I format a MVC3 WebGrid date column for local timezone?

My datetime values are stored as UTC in the database. I want to display them in the local timezone using the standard MVC3 WebGrid control, but don't have a clue how to do that or where to look for the answer.

My current code looks like this:

grid.Column("TestDateTime", "Test Date/Time")

and I know THAT doesn't work!

Can somebody steer me in the right direction? I do have access to the Telerik controls (free from the local user group) but have not tried them as it seems the more add-ons the more hassle (license fees, updates, keeping several dev environments in synch, etc). If it's the only way to go I will do it, but would rather get Microsoft's standard tools to do the job.

Thanks, Dave

-------------Problems Reply------------

Try something like :

grid.Column("DueDate", "Due Date", format: (item) => String.Format("{0:yyyy-MM-dd}", item.DueDate))

you can do pretty much anthing you need afer the format: marker

Category:c# Views:0 Time:2012-03-06

Related post

  • Pivot Table Conditional Formatting not sticking on Data columns 2012-06-02

    Hello everyone, I am using Excel 2007 and am using a Pivot Table with Conditional Formatting. The formatting works fine in the columns that are defined in the "Row Labels" section (i.e. the leftmost columns). However, even though I specifically inclu

  • How to convert time to date in the local timezone during query 2011-12-28

    We have a very simple payments model with the default "created_at" datetime field that we have to search in a date range so I did this: >> Payment.all(:conditions => ["Date(payments.created_at) >= ? and Date(payments.created_at) <= ?",

  • XSLT 1.0: Converting date/time to local timezone 2012-03-10

    My XML has a tag with the two separate properties, formatted_date which has day.month.year format (e.g. formatted_date="02.10.2012") and time which has a hours:minutes format (e.g. time="23:00"). I'm trying to find a way to convert these somehow to m

  • Converting varchar column to date column in Oracle 2012-03-08

    I need to change column type from VARCHAR2 to DATE. The column is already storing dates in correct format. So I was trying to do something like this alter INM_INCIDENT rename column INM_I_REACTION_TIME to INM_I_REACTION_TIME_OLD; alter table INM_INCI

  • MVC3 WebGrid Formatting or Styling Column Headers 2011-02-01

    I'm using the new MVC3 WebGrid. So far so good, just having issues styling/formatting the column headers. The best I've got is a workaround that applies the same css class from the first row of the WebGrid to the table header. var headerCells = $("#g

  • How to hide header on MVC3 WebGrid 2011-01-17

    Is there some easy way to hide header for MVC3 WebGrid extension? Something like var grid = new WebGrid(Model, canSort:false, canPage:false, showHeader:false); I can probably set css style for header that will cause header not showing, though I'd rat

  • Server side paging for MVC3 Webgrid 2011-06-21

    I have looked at a number of examples (e.g. http://www.dotnetcurry.com/ShowArticle.aspx?ID=618 and http://msdn.microsoft.com/en-us/magazine/gg650669.aspx) but it seems very manual and convoluted. The reason I would like to use the WebGrid is that the

  • MVC3 Webgrid Paging and Sorting 2011-07-18

    I'm using MVC3 webgrid to display, sort and paginate data. The display is fine, but when I click on a new page or request a sort, it opens the table in a brand new window on it's own? Anybody know why this happens? It is contained within a partial vi

  • Based on Model Column Value(true/False) in MVC3 Webgrid , How can Add a Link as column in diplaying the rows 2011-07-18

    I am using MVC3 Webgrid. I have model which has column of type bool. Based on the Value of this coulumn I need to render a coulmn , with hyper link. If the bool column value is true then I have to render Record, else Edit. Could you kindly give the s

  • Why aren't MVC3 webgrid paging and sorting working? 2011-11-04

    I'm using MVC3 webgrid to display, sort and paginate data. The display is fine, but when I click on a new page or request a sort, nothing is happening. This is the code that I'm using: @if (Model.AdsList != null) { WebGrid adGrid = new WebGrid(Model.

  • MVC3 WebGrid toggling sort direction 2011-11-12

    With an ASP.NET MVC3 WebGrid how can I setup the column sorting such that clicking on the column heading toggles between ascending sort and then descending sort? Thanks! Rob --------------Solutions------------- The underlying problem turned out to be

  • Handling Null Values in MVC3 webgrid 2012-01-05

    Can someone please explain me how to handle null values in mvc3 webgrid? --------------Solutions------------- The question is a little vague but I believe you can use the null coalescing operator ??. This question here shows dealing with a null value

  • Display tooltip on mouseover event in MVC3 WebGrid 2012-02-13

    I have a MVC3 WebGrid in my View.I want to display a tooltip when the mouse hovers over any row, displaying information coming from the server. I have already seen this link: Show a tooltip with more info when mousover a MVC3 Razor WebGrid row My poi

  • ASP.NET MVC3 WebGrid - custom, server-side sorting 2012-04-12

    Is there a way to override default MVC3 WebGrid sorting behavior to call my controller (which will perform server side sorting and return the data) when sort is called? Thanks for any help! --------------Solutions------------- You can pass the server

  • Format a Microsoft JSON date? 2008-10-15

    I'm taking my first crack at Ajax with jQuery. I'm getting my data onto my page, but I'm having some trouble with the JSON data that is returned for Date data types. Basically, I'm getting a string back that looks like this: /Date(1224043200000)/ Fro

  • How do you use a binarywriter to write the correct MS SQL native format for the Money data type? 2009-02-18

    How do you use a binarywriter to write the correct MS SQL native format for the Money data type? I'd like to take a value in .net, read from a file as string representation of a decimal amount (actually an exported "Money" data type from SQL, but tha

  • binary format to pass tabular data 2009-04-19

    I'm maintaining a legacy embedded device which interacts with the real world. Generally speaking, this device collects data from sensors, processes the data using its internal algorithm, and displays warning when data reaches a certain "bad" state. F

  • How to convert python date format to 10-digit date format for mysql? 2009-05-16

    how to convert python date format to 10 digit date format for mysql example: date in python -> 11-05-09 to something like 1239992972 (10 digit) Thanks --------------Solutions------------- You can use the time module's strptime - you pass in a stri

  • Changing the format of the UI date picker 2009-11-05

    I am using the UI datepicker and I have already limited the date range possible, bt now, I also want to change the format becuase my mysql database is not storing the dates as the format is not the ISO format(yyyy-mm-dd), it is more like(dd-mm-yy), h

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.163 (s). 11 q(s)