Friday, September 16, 2011

truncate a DateTime in Razor with jQuery

In a Razor control such as this:

@Html.EditorFor(model => model.Foo)

 
 

...a DateTime will appear as 1/1/2011 12:00:00 AM unless one proactively alters its appearance. The following is a trick to make the date appear as 1/1/2011

<script type="text/javascript">

   (function () {

      var thinDate = $('#Foo').val().split(' ')[0];

      $('#Foo').val(thinDate);

   })();

</script>

No comments:

Post a Comment