I have an array, one key is createDate. In a foreach looping of the array, I pull the createDate value via a knockout text binding.
<span data-bind="text: createDate"></span>
The value displays: '2013-04-24T16:29:00.38' ... this is the way it exists in the database. Is there a way to format (within the binding) to show just the date only? Or do I have to save it as date only in the database to achieve this?
E.g., you can use the following to set 2 decimals:
<span data-bind="text: price.ToFixed(2)"></span>
Is there something simple such as this to only display: '2013-04-24'
Thanks in advance !
For me the key is moment.js
You can do something as simple as this:
<span data-bind="text: moment(createDate()).format('MM/DD/YYYY')"></span>
Or you could write a binding helper like this guy does, so it would be something like:
<span data-bind="dateString: createDate, datePattern: 'MM/DD/YYYY'"></span>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With