2

How can I write filter function for get date from datetime string in angularjs

My date string is

2015-03-17 00:00:00

I want to get only 2015-03-17.

My code is,

<span class="pull-right"> {{quotationDetails.quotation_date| date : "yyyy-MM-dd" : "'+0430'"}} </span>

but it is not working,display nothing.How it resolve?

0

3 Answers 3

1

You can get required output by below changes, Date format and Timezone don't require double quotes instead enclose them only in single quotes as in below example.

<span class="pull-right"> {{quotationDetails.quotation_date| date : 'yyyy-MM-dd' : '+0430'}} </span>

Hope this will solve your issue.

Sign up to request clarification or add additional context in comments.

Comments

0

You are using a string. Date filter takes a Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). As pointed out in the docs

Try setting quotationDetails.quotation_date to new Date('2015-03-17 00:00:00')

Here is a working example

2 Comments

how can I use new Date inside ng-repeat for an input value?
@ShihabudheenMuhammed you could just use type="date" for your input field. Check this and the docs and there is also datetime and this is recommended by the angular team for date input
0

Try parsing the quotation_date first, try this:

function Scoper($scope) {
    var string = "2015-03-17 00:00:00";
    $scope.quotationDetails = {
        dateNow: Date.now(),
        stringDate: string,
        quotationDate: Date.parse(string)
    }
}

Here is the working sample: http://jsfiddle.net/rainercedric23/aubmfogv/4/

5 Comments

where should I put this function? or how can I invoke?
where did you get your data exactly? you can just create another variable that is equal to your string Date like quotationDate= Date.parse(string) please see my fiddle so you can play the code the way you want.
Have I answered your question? if yes, please accept it, Thanks! or if there's lacking just tell me..
not resolved.I want to use like as a filter.how can I use this function as filter?
As in you want an input date then it will function as a filter to that input? Am I right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.