angular date filter no effects - angularjs

I have date in this format
2016-05-22 08:00:00
I am trying to apply a filter like this
<td>{{ event._source.event_date | date : "dd.MM.y"}}</td>
but this does notthing.
What am I missing?

The date pipe requires the value of type Date. A value of string is currently not supported (but work-in-progress).
You can convert the date using new Date('2016-05-22 08:0:00') (not checked if the format is correct and accepted though)

Angular 1:
Add following function to your scope to get Date object from your string. First it converts your string with date to format YYYY-MM-DDTHH:MM:SS (adding 'T' between YYYY-MM-DD and HH:MM:SS).
$scope.isoDate = function(dateString) {
return new Date(dateString.split(' ').join('T'));
};
Now you can use it:
{{ isoDate(event._source.event_date) | date : "dd.MM.y" }}
See jsfiddle

Related

Create current date in String format and parse to date as string in Apex

Goal:
I need to first create a String representing the current date.
Afterwards this String needs to be parsed and used to build an instance of the Date class.
Initial attempt:
In my test class I create a current date as a String input for my tested method in the following manner:
String inputDate = date.today().format(); // 13:28:15:378 USER_DEBUG [24]|DEBUG|17.3.2017
However, when I attempt to create an instance of a Date object like this:
Date dateFromInput = date.valueOf(inputDate);
I receive the following error:
13:28:15:398 FATAL_ERROR System.TypeException: Invalid date: 17.3.2017
Following code
((DateTime)Dob).format('YYYY-MM-dd')
Just Works
Date.format() will return string in current local date format of logged in user.
Date.valueOf needs input string in format yyyy-MM-dd HH:mm:ss in the local time zone.
Below should work:
String inputDate = date.today().format('**yyyy-MM-dd HH:mm:ss**');
Date dateFromInput = date.parse(inputDate);
In the documentation, there is a difference between the parse and valueOf Date methods that escaped me:
parse(stringDate)
Constructs a Date from a String. The format of the String depends on the local date format.
valueOf(stringDate)
Returns a Date that contains the value of the specified String.
What I wanted was the parse:
String inputDate = date.today().format(); /
Date dateFromInput = date.parse(inputDate);
You can try Moment.apex. Here is the link
Datetime dt = new Moment('2018/01/12 10:00:00', 'yyyy/MM/dd HH:mm:ss').toDatetime();

Time shown incorrectly from Angular

Usually code like as:
html
<p class="small-grey-text float-left">
{{ product.date-created | date:'MMMM dd, yyyy ' }}
</p>
json
[{"date-created": 1475798400 }]
This is must look as October 07, 2016
Result
January 01, 1970
It looks like you are having the same problem as in this thread. The date pipe format is correct you need to multiply out the date by 1000.
date-created or dateCreated is word of element for JS.
Let me that is like with working - date_created or datecreated

Importing Dates into R from SQL Server

I am trying to query a SQL Server database to check for the MAX date in one field and to select the next day for input into another process. I am able to query the database and pull back a date, but I can't convert it into a date object.
Here is what I tried:
tmpMaxDate <- sqlQuery(dbhandle, 'select MAX([date]) + 1 from dbo.My_Data ')
tmpMaxDate
1 2016-01-02
IsDate(tmpMaxDate)
[1] FALSE
maxDate <- as.Date(tmpMaxDate)
Error in as.Date.default(tmpMaxDate) :
do not know how to convert 'tmpMaxDate' to class “Date”
maxDate
NULL
IsDate(maxDate)
[1] FALSE
maxDate <- as.Date(tmpMaxDate, format = "%Y-%M-%D")
Error in as.Date.default(tmpMaxDate, format = "%Y-%M-%D") :
do not know how to convert 'tmpMaxDate' to class “Date”
IsDate(maxDate)
[1] FALSE
maxDate
NULL
The packages I am using are RODBC, chron, lubridate, and RSQLserver
I thought I needed to convert to a date object to use the date from SQL Server in R.
Any thoughts on why my date won't convert? Do I need to convert to be able to use that date to filter data in R?
DateVar <- sqlQuery(dbhandle,"SELECT CONVERT(varchar(10),GETDATE() + 1,101) as Date")
DateVar
NewDate <- as.Date(DateVar$Date, format = "%m/%d/%y")
NewDate
I think the trick for me to was give the date response a column name and then reference the column (being the specific string value needed to convert) name in the conversion.
class(NewDate)
will show as "Date"

AngularJS : display epoch in pst/pdt using date filter

I am getting date in epoch format from the backend.
updatedOn = 1427171737000 (from backend)
I am using angular filter to display the date.
{{updatedOn | date: "MM/dd/yyyy ' ' h:mma Z" }} ==> it turns to be 2015-03-23 21:35:37 -0700
I would like my output to be displayed in PST format which will be 2015-03-24 04:35:37
Any ideas?
If you are using 1.3+ of AngularJS then you just need to pass in the timezone
{{ date_expression | date : format : timezone}}
https://code.angularjs.org/1.3.15/docs/api/ng/filter/date if you want to read further.
{{updatedOn | date: "MM/dd/yyyy" : 'PST' }}

Get month from datefield

I using Django-rest and I want to get month form Datefield in AngularJS.
My code is date = '2014-2-30' and I get month: var x = (new Date (Date.parse (date).getMonth().
But x = 1 and value of year = 114.
I read https://docs.angularjs.org/api/ng/filter/date but I can't do it. Would you give me example?
Django REST Framework should pass dates back to Angular in ISO 8601 format (yyyy-MM-dd), so there shouldn't be an issue parsing it on Angular's side.
{{ obj.date | date:"MMMM" }}
MMMM is the Angular date code for the full month (January-December). You can find other Angular date codes in the date filter documentation.

Resources