How to set two way binding for a date object? - datepicker

I'm trying to implement DatePicker to return a Date Value similar to this example in Angular 6
https://stackblitz.com/angular/klxqgnondlx?file=app%2Fapp.component.html
It works great . . . . . . . but it returns a JSON date rather than Date object, so the two way binding with a corresponding date field doesn't work.
I need the date picker to return Date object not JSON
Here is what I tried
<input class="form-control" type="date" placeholder="yyyy-mm-dd"
id ="myDate" name="myDate" [(ngModel)]="model.myDate| date:'yyyy-mm-dd'" ngbDatepicker #d="ngbDatepicker" (ngModelChange)="myDate= $event" >
But it didn't work

What is returned is up to the library you are using. You could always use a different library. It might be easiest to just make your model a string (representation as JSON date), and convert it to a Date object when you actually need to use the Date representation.

Related

SendGrid - formatDate with Insert tag definition - Error

I am trying to format the date using formatDate. None of the options is working in terms of formatting the date. Please suggest. We are using the insert tag to fetch values from the template.
{{insert notes_lead_creation_date}}
This date has to be formatted to DD/MM/YYYY. Currently the date has : notes_lead_creation_date:2058-07-25
Also, getting an error message.
This message has been dropped.
As per the documentation, you cannot format a date within an insert helper. If you are using insert to provide a fallback, you should use a conditional, like so:
{{#if notes_lead_creation_date}}
{{ formatDate notes_lead_creation_date "DD/MM/YYYY"}}
{{else}}
default content
{{/if}}
Note that the date must be provided in ISO8601 format too.

Grails: error executing tag <g:formatDate>: unknown class: java.lang.String with root cause

I have dates stored in my database in a format like this: 2017-04-12T00:00:00
I am displaying these on an index show page like so:
<td>${event.eventTime}</td>
I want to convert the date into a a regular format, I came across the grails formatDate tag.
I've tried variations of this but the error from the title still remains, where am I going wrong?
<td><g:formatDate date="${event.eventTime }" format="yyyy-MM-dd" /></td>
It appears that eventTime on your event object is a string rather than a date.
If you try the following as a test it should work:
<td><g:formatDate date="${new Date()}" format="yyyy-MM-dd" /></td>
Is eventTime stored as a date in the DB or maybe it's being converted en-route to the gsp?
To just strip off the time & keep the same format you could:
${event.eventTime?.substring(0, 10)}
Or you could convert to a date and back to another format:
<g:formatDate date="${Date.parse( "YYYY-MM-dd'T'hh:mm:ss", event.getTime )}" format="yyyy-MM-dd"/>

Set initial value of DateInputElement

I need to set intial value for DateInputElement. The .dart file has a variable dob with initial value:
String dob='01/01/2013'
and html has
<input id='mydob' type='date' name='dob' required='true' bind-value='dob'/>
dob is not shown when UI is displayed. The control shows mm/dd/yyyy.
If I select a date on UI, the date value is populated in dob variable.
Although bind-value sets two way binding, still tried setting the value to dob as follows without success:
<input id='mydob' type='date' name='dob' required='true' value={{dob}} bind- value='dob'/>
Also tried the following in life cycle events but did not work:
DateInputElement e = query('#mydob');
e.value=dob;
The format you are trying to put into the field is wrong. It's supposed to be 2013-01-01 (YYYY-MM-DD) according to the RFC. This is completely independent from dart or any other binding.
I would add that it is nessary to have the 0. So it is 2013-01-01 and not 2013-1-1

struts 2 s:date tag with value from variable in request with it's name in request

I have a problem in my web app with struts 2 and a date value. I've got a form and inside it an s:textfield that shows a date value. I read this value from request, and the problem is that the name of that value is in other variable.
The Action I'm calling does this:
...
public String execute(){ return SUCCESS;}
public MyObject getObject1(){
MyObject result = new MyObject();
result.setDate(new java.util.Date());
return result;
}
...
On SUCCESS it goes to my form.
The code in my form (what I was wondering to write) is:
<s:form action="save">
<s:set name="objName" value="object1"></s:set>
<jsp:include page="../includedform.jsp"></jsp:include>
</s:form>
And in the "includedform.jsp" there is:
<s:textfield name="%{objName}.date" label="Date" >
<s:param name="value">
<s:date name="%{%{objName}.date}" format="dd/MM/yyyy" />
</s:param>
</s:textfield>
The syntax:
%{%{objName}.anagrafica.dataNascita}
doesn't work (it shows nothing, obviously). So i'll need something like this but working :)
Other tags s:textfield inside "includedform.jsp" (ommited in the code bellow for simplicity) without date fields are working, because I am using only the name attribute and struts looks automatically for the value. This is the code I use for these textfields:
<s:textfield name="%{objName}.name" label="Name"/>
your question is very confusing and you need to rephrase to make it more clear and readable.
i am not sure why you are doing this
<s:textfield name="%{objName}.date" label="Date" >
while this can be done like
<s:textfield name="objName.date" label="Date" > OR
<s:textfield name="%{objName.date}" label="Date" >
when you write objName.date OGNL assume that you have a bean in your action class namely objName and this bean has property namely date, s ultimately this will get converted to
getObjName().getDate() by ONGL
On a similar fashion <s:date name="%{%{objName}.date}" format="dd/MM/yyyy" /> datee tag works
For more details please refer to the official doc
Struts2 Date tag
There is one solution which i tried and it worked :)
1)Keep the column in which you want to store date in database's table in "DATE" data type only.
2)Use only Textfield tag in JSP page.Dont use Date tag.
Note:Make sure that you make user input date in YYYY-MM-DD format only by placing a placeholder in textfield tag !
3)Keep the variable for accessing that field of string type only.Dont use DATE data type.
4)Now run Query: Select DATE_FORMAT(datecolumnname,'%d/%m%/Y') as date_two from tablename; and you will get date from that columnin dd/mm/yyyy format even if it is stored in YYYY-MM-DD format in table .
5)And you can also compare your datecolumn's data with curdate() and related functions as well and it works :) .
6)Like i used query: Select id,name,DATE_FORMAT(datecolumnname,'%d/%m/%Y') as datecolumn2 from tablename where datecolumnname >= curdate();

jquery datepicker date format with output of Zend_Locale

I'm trying to set the format for a jquery datepicker element with the date format returned by Zend_Locale::getTranslationList('date', $locale);
My problem is zend returns the string 'dd/MM/yyyy' for the date format but jquery expects only 2 characters for the year ie 'dd/mm/yy', so it enters the year twice 20112011
Is there some option that can be passed to either zend or jquery to make them work in the same manner? I've read through the docs and can't seem to find anything
Many thanks for your help in advance!
I have used jquery date picker in python-django framework when I give date format as dd/mm/yyyy format it returns 20112011 then i have corrected it to dd/mm/yy and it returned 2011 only. you can specify in your datepicker css class to specify the date format as dd/mm/yy.
Iam not sure if this is what you're looking for but:
// use german local, change it to our needs :-)
$locale = new Zend_Locale('de_DE');
$result = Zend_Locale::getTranslationList('date', $locale);
// returns dd.MM.yy (german!)
echo $result['short'];