0

I have a date that is being being returned in the format:

2016-07-25 10:50:14

I've created a variable that gets the data and strips out the dashes, spaces and colons with:

var newDate = $scope.details["Created At"].replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '');

Now the with console.log(date); the date is being returned as:

20160725105014

I guess my main question is how can I take that variable data and add it back into the controller $scope so that I can call it into my html and use angular date formatting such as:

{{ details.newDate | date:'MM/dd/yyyy @ h:mma' }} 

Thanks for any help.

2 Answers 2

1

Should be something like

$scope.details.newDate = $scope.details["Created At"].replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '')
Sign up to request clarification or add additional context in comments.

1 Comment

Yep that worked. With {{ details.newDate }} it shows "20160725105014" . but know I have just created a new issue when I use " {{ details.newDate | date:"MM-dd-yyyy 'at' HH:mm:ss" }} " it returns "null". So I will start a new question for that issue. Thanks for the help and the quick response!
1

Once you have your desired value in a variable "newDate" you can then assign that same variable to some other $scope variable to be used in your view.

var newDate = $scope.details["Created At"].replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '');
$scope.myStrippedDate = newDate; 

1 Comment

Please edit with more information. Code-only and "try this" answers are discouraged, because they contain no searchable content, and don't explain why someone should "try this".

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.