The following line outputs the string "30.11.-0001" in case the date is "0000-00-00".
{{ payment.pay_date | date: 'dd.MM.yyyy' }}
How do I make it output a blank string in case the date is "0000-00-00"? (if possible, without using if clauses or directives)
The code above has some syntax error. Please try this one. This is perfect and it worked for me very well.
((dtItem.DueDate !== '0001-01-01T00:00:00') ? (dtItem.DueDate | date: 'dd/MM/yyyy') : '' )
use a custom filter , so its reusable in your app
for example,
app.filter('hideIfEmpty', function($filter) {
return function (dateString, format) {
if(dateString === '0000-00-00') {
return "";
} else {
return $filter('date')(dateString, format.toString());
}
};
});
you can use this by
{{ payment.pay_date | hideIfEmpty: 'dd.MM.yyyy' }}
if date is equals to '0000-00-00'
then return a empty string , or you can return something u like, if is not equals to '0000-00-00'
then format the date according to the format and return.
here is the example fiddle (its not output something because filter return empty string ""
use a correct date and test to check. :) )
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