I have a form with several fields. One of those fields has xtype of datefield. Values for this form come from a json file, which looks like so:
{"field_1":"text value", "field_2": "2017-08-16T21:00:00.000Z"}
However, when I do:
form.setValues(json);
only the first field is set. The second datefield, which is defined like:
{
"xtype":"datefield",
"name": "field_2"
}
is not set for some reason. What is wrong with that and how can I fix it?
Because JSON does not support javascript dates natively, the value in field_2 is a string, not a javascript date.
While a string can represent a date, there are a variety of formats. In this case the string is in a format unrecognized by datefield. When the datefield tries to set the value, it will try to parse the string into a date, but since your selected format is not one known to datefield by default, the value is set to null.
The format and altFormats configs contain the formats datefield recognizes, and can be exchanged/amended to contain the date format(s) you want to support.
Related
There's column which contains date in different formats (ie. YYYY-MM-DD or YYYY-DD-MM).
When I query it with format time:date, it throw an error: date/time field value out of range: "2022-23-02"
How can i solve it?
How can I check if it's YYYY-MM-DD or YYYY-DD-MM or another?
If you have no field that tells you whether it's YYYY-DD-MM or YYYY-MM-DD, you are kinda out of luck because it's possible that a value could be valid in both formats.
If you are able to redesign, and you must store the date as a string then use YYYY-MM-DD as it's easier for sorting. Optimally, just pass a JavaScript Date object to field of type date, timestamp, or timestampz to the database driver or orm and let it handle the conversion for you. Here's an example with node-postgres: https://node-postgres.com/features/types (the section labeled "date / timestamp / timestamptz")
Problem
I am working on an email template text whereby I would like to change the date DD/MM/YYYY to MMMM. There are two instances of it in the template. The two instances belong to 2 different date fields however their configuration is the same. Let's say I have date_field1 and date_field2. When I do the following in date_field1 it works fine but in date_field2 it doesn't and I get the following error.
I have checked the type of mydate just to make sure and it is a date. When I just do ?string it works fine and it does contain a date value but with .MMMM, it throws an error. Any help or suggestion will be great.
Code
Working: <#assign mydate1=transaction.date_field1 /> ${mydate1?string.MMMM?lower_case}
Not working: <#assign mydate2=transaction.date_field2 /> ${mydate2?string.MMMM}
Error
If you have an actual date field the format string is like:
<#assign mydate=transaction.date_field2?date["MMMM"]>
And of course there is no field called date_field2 so I assume that label is meant as a simplified example.
Note you can also try:
<#assign mydate=transaction.date_field2?string["MMMM"]>
But I think that was for a more recent version of Freemarker than Netsuite supports.
Finally you can set the overall string to date format which will be in place from the place in your code down to wherever you reset it. I found I had to set it for both date and datetime because some 'date' fields are interpreted by Freemarker as datetime even when they shouldn't be:
<#setting date_format="MMMM">
<#setting datetime_format="MMMM">
${transaction.date_field2}
In typescript, I am setting an object's date field in following way.
at: new Date("2017-06-24"+"T"+"22:00"+"Z")
Then I am sending that object as POST body to my webservice. In body, date field looks like "at":"2017-06-24T22:00:00.000Z"
But I want o get rid of milliseconds part. How can I do that ?
You can format the String you have from the form input values as
new Date("2017-06-24"+"T"+"22:00"+"Z").toISOString().split('.')[0]+"Z"
else you can directly generate the String from your form input values
`${this.form.value.Date}T${this.form.value.Time}Z`
in both the above cases you have the String output as 2017-06-24T22:00:00Z
and not the Date type.
Date constructor in Js will have the milliseconds field
so it will be an issue if at in your Object is defined as a Date instead of a String.
I have saved date as a string.
for example:
I have object in angularJs called myBirthday.
myBirthday.date="1996-04-04";
and I want to show the date in input in the modal:
<input type="date" ng-model="myBirthday.date" />
The problem is that it's shown dd-mm-yyyy instead of 04-04-1996.
Then When I change the date,close modal and then reopen it,The input shows the correct date.
How can I make it to show the correct date? not dd-mm-yyyy?
I have tried almost every string types of date.
please HELP
You shoud create a Date object instead of a String.
myBirthday.date = new Date(1996, 3, 4);
You could also cast the Date to a String:
date_string = myBirthday.date.toISOString();
It seems date filter called before binding of date or date-format values. date/dateformat is null initially but filter called that's why filter would be giving default format string. And once values are binded properly then everything works perfectly fine
I'm using a 0:dd/MM/yyyy as format and textTemplate for the DatePicker object
$('#datePickerSelector')`.shieldDatePicker({
format: "{0:dd/MM/yyyy}",
textTemplate: "{0:dd/MM/yyyy}"
});
When the user select the date from the selector in the proper way the format is correct when I retrieve the value using:
$('#datePickerSelector').val();
But whenever the user manually type in the date in the text box (for example 1/5/2015, the value retrieved using the same sentence above is (05/01/2015).
How can I fix this?
You need to use the parseFormats option of the datepicker. It contains an array which contains list of date formats used to parse the value set with value() method or by direct typed user input. In your case you need to add dd/MM/yyyy in the array:
$('#datePickerSelector').shieldDatePicker({
format: "{0:dd/MM/yyyy}",
textTemplate: "{0:dd/MM/yyyy}",
parseFormats: ["dd/MM/yyyy"]
});