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
Related
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}
I am using Bootstrap datepicker and on selecting different values from a list its startdate is changing. It is working fine if I set the startdate 2013 from 2008 but it doesn't work if a select start date 2008 and currently its 2013.
What could be the reason here?
$('#datepicker').datepicker('setStartDate', updatedDate);
This line I am executing whenever I select different startDate.
Really need to know what updatedDate value is.
However, if you read the docs for the dtepicker the value passed in must be a string that is understandable by format
https://bootstrap-datepicker.readthedocs.io/en/latest/methods.html#setstartdate
https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#startdate
Date or String. Default: Beginning of time
The earliest date that may be selected; all earlier dates will be
disabled.
Date should be in local timezone. String must be parsable with format.
So what you pass in as the format option must match the format of your start date. If you do not set the format optin, the default is "mm/dd/yyyy"
Without seeing code, I can only hypothesize; try calling [...].datepicker('update', 'date_string'); on the object to force an update on the control.
I have the following piece of code that displays an input area and a datepicker popup
<input close-on-date-selection="false" type="text"
id="startDate" datepicker-popup="dd.MM.yyyy"
ng-model="myCtryl.startDate"
max-date="myCtrl.maxDate"
datepicker-options="myCtrl.dateOptions"
ng-change="myCtrl.validateDate()"/>
The date model is bound to startDate variable. My problem is, initially this startDate variable is in string format. When I debug startDate variable at the opening of the page, it looks like:
Whenever I make a selection on the datepicker, this variable turns into date format. Following is the screenshot of the variable after I select a date from the datepicker:
Here are the related parts of the controller. Initially I show today's date on the input area of the datepicker:
vm.todayDt = new Date();
vm.todayDt = $filter('date')(vm.todayDt, 'dd.MM.yyyy');
vm.startDate = vm.todayDt;
Here, the filter might be the problem. I tried removing that line too. When I removed that line, startDate became a date object at initial state too, but this time it shows "28.20.1614" on the input of the datepicker:
even though the dateobject is correct when I debug the variable:
What can I do to make the date object and the input area consistent? I.e., the object should be always in date format and it should show correctly on the input area. Thanks.
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"]
});
I'm struggling to set a value on the input of type="date" in google chrome: http://jsfiddle.net/ruslans/gNv7H/
<input data-bind="value: dateString" type="date"></input>
var viewModel = {
someDate: new Date(parseInt("/Date(1367708400000)/".substr(6)))
};
ko.applyBindings(viewModel);
My date will come from JSON data but first I need to find out which format does it need to be in for Chrome's date picker to recognize the binding. Would I have to do it with jQuery selector and set .val() on the field? Seems daft...
Edit: according to this article, the date format to set the value on Google date input must always be "yyyy-mm-dd". Which is a pitty, because we're using jQuery date picker for all browsers where there's no native date pickers exist.
You just need to correctly format your value as described in the W3C working draft:
A valid full-date as defined in RFC 3339, with the additional qualification that the year component is four or more digits representing a number greater than 0.
Example:
1996-12-19
So the following should work:
var viewModel = {
dateString: ko.observable('2002-02-02')
};
Demo JSFiddle.