I'm trying to create a textbox that accepts mm/yy. For some reason this doesn't like dates beyond 2032. Can anyone tell me why not and what the solution is?
Update: Problem appears to be strictly a 2 digit year issue.
<input type="text" class="miniTextBox" id="${id}_Date" name="${id}_Date" maxlength="5"
data-dojo-attach-point="indate"
data-dojo-type="dijit/form/DateTextBox"
data-dojo-props="constraints:{fullYear: false, datePattern: 'MM/yy', max: '2099-12-31'},
popupClass: 'dojox.widget.MonthAndYearlyCalendar'"
promptMessage="Example: 10/14" />
If it makes any difference, the following information may be helpful:
Uses Dojo 1.8
This is part of a widget template
There is a postCreate modification on this widget to set the fullYear constraint to false.
It does not use the standard popup calendar, and it doesn't matter if the date is entered by the popup or from the textbox.
the problem appears to be strictly a 2 digit year format issue - it works fine when the date format is changed to MM/yyyy and fullYear is true.
In case anyone is still wondering, this is expected behavior. See documentation.
When two digit years are used, a century is chosen according to a sliding window of 80 years before and 20 years after present year, for both yy and yyyy patterns.
2033 was just outside that window in 2013 and 33 was interpreted as 1933.
Related
I need to get the difference in hours and minutes of two times. For example 8:30AM and 2:14PM. I need to be able to subtract these to hours in Adobe Sign Formula expression. The supported function seem to support date based fields and not necessarily work right with only time. Here is the support page:
Add calculated fields to a form
I tried using datePart(part, date) and parsing first the hour and then the minutes. The problem is that this works if the value is a PM time (3:00PM) but if the value is an AM time (7:30AM) the function returns 0 instead of 7 (in the hours case)
datePart("h", "08:00:PM") = 8
datePart("h", "07:30:AM") = 0
I found out how to do this:
When creating the fields, make sure they are of type text and that the properties are as shown in the following image:
Notice the date format is a custom and with format h:nn tt, meaning that it only accepts values like 12:25 PM and 1:35 AM (no lower case am or pm). So suppose you have two fields like these: time_test1 and a time_test2, the third field instead will contain the number of hours will have this properties setup:
So, clicking on the F(x) in order to expand the formula expression, you need to put the following formula: dateDiff("h", [time_test2], [time_test1])
Also, click on Check syntax to make sure that it’s valid
Here is how it would look when I sign:
I hope this can be useful to others.
This question already has answers here:
ToLocaleDateString() changes in IE11
(5 answers)
Closed 4 years ago.
new Date().toLocaleDateString('en-US'); // "8/17/2018"
new Date("8/17/2018") //valid date
new Date(new Date().toLocaleDateString('en-US')) // Invalid Date
I am trying to create date from local date
string (see screenshot) but its not working in IE11 only. It works with normal date string though.
I know something wrong with "" double quotes but not able to get it working.
Any suggestion ?
Seems it can be done like this
new Date(new Date().toLocaleDateString('en-US').replace(/[^ -~]/g,''))
Reference Answer
just use momentjs for this.
moment("8/17/2018", "L").format() would output:
"2018-08-17T00:00:00+02:00"
(+02:00 is my local timezone. you can specify to use utc or another timezone too.)
also keep in mind L is dependent on the timezone profile you installed. this is the default en one.
you could also replace "L" with "MM/DD/YYYY"
the second argument of moment always specifies the format of your input.
it is also able to guess the input but you need to experiment with that.
.format("L") is essentially the same but in the output direction.
I have a bug in my jquery ui datepicker. I have the format: mm/dd/y , and for example the year is: 1915. So, 7 February 1915 will be: 02/07/15. After I select this date and close the datepicker, I can see with Firebug Inspect that the year is well saved, it's 1915, but when I open the datepicker again, the year selected is 2015 and not 1915.
I'm using jquery-1.9.1 and jquery-ui-1.11.4.
I'm also using this library: https://github.com/trentrichardson/jQuery-Timepicker-Addon
Any idea on how to fix this?
I found the problem and the solution.
The problem was that somwhere in my code I used "setYear" function. According to: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getYear I found that:
For years greater than or equal to 2000, the value returned by getYear() is 100 or greater. For example, if the year is 2026, getYear() returns 126.
For years between and including 1900 and 1999, the value returned by getYear() is between 0 and 99. For example, if the year is 1976, getYear() returns 76.
For years less than 1900, the value returned by getYear() is less than 0. For example, if the year is 1800, getYear() returns -100.
This website also suggested the solution:
To take into account years before and after 2000, you should use getFullYear() instead of getYear() so that the year is specified in full.
Thanks for trying to help. I hope this will also help others in the future. Don't use setYear function, use setFullYear instead.
I'm running to an issue I'm not sure how to resolve it; so the deal is that I have a function of javascript that take the date selected from the user and depending of another selection it adds to the date 6 o 12 months, the weird thing is that when you select a date of June, and make it add the 6 months I get a return value of 0 months, and it should be 12 for December, also If you choose December and add 12 months I'm getting a 0 as a return value. So here is my code
var date1 = $("#date_begin").val();
var days= date1[0] + date1[1];
var month= date1[3] + date1[4];
var year= date1[6] + date1[7] + date1[8] + date1[9];
var actualDate = new Date(year,month,days);
actualDate.setMonth(actualDate.getMonth() + 6);//add 6 months
$("#date_finish").val(actualDate.getDate()+"-"+actualDate.getMonth()+"-"+actualDate.getFullYear());
I'm printing the date directly to the text box as you can see. Also for the selection of the date in the first box I'm using the datepicker of jquery with this option selected
$("#date_begin").datepicker("option", "dateFormat", "dd-mm-yy");
I have been trying to fix this but I have no idea how to do it.
Hope you guys can give me a hand.
Months are indexed from 0.
June is 5 not 6.
What you have calculated is actually July (6) + 6 months = January (0) of the next year.
If you can get the date string into a format accepted by Date's constructor, that might be an easier way to create your date object. Though you need to be aware that there are some differences between browsers when it comes to the formats that are accepted.
If the date comes from users, then you should use a date format that makes sense for your users, and if necessary use a library that can work with that format of date.
When the date comes from communications with the server, I like to use the same format produced by JSON.stringify (dates that look like 2015-06-09T21:42:25.816Z), and I use es5-shim.js to make sure that the new Date(string) constructor can read strings in that format.
There is some information about parsing date strings using the new Date(string) constructor on Mozilla's developer site.
I am currently writing some sort of javascript based client calendar and observed some issues. All over the net, I can find code samples, where people use day overflows in the Date constructor.
i.e.
// get the first day of the next month
var myDate = new Date(someDate.getFullYear(),someDate.getMonth(),32);
myDate.setDate(1);
The general idea of this concept is, that since there is no month with 32 days, the constructor will create a date within the next month. I saw even codesample with negative overflows:
i.e.
// get the last day of the previous month
var myDate = new Date(someDate.getFullYear(),someDate.getMonth(),1);
myDate.setDate(-1);
Now while this seems to work in many cases, I finally found a contradiction:
// this prints "2012-12-30" expected was "2012-12-31"
var myDate = new Date(2013,0,1);
myDate.setDate(-1);
Further examination finally revealed that dates like
new Date(2013,0,23) or new Date(2013,0,16) combined with setDate(-1) all end up in "2012-12-31". Finally I observed that using -1 seems to subtract two days (for getting the expected result setDate(0) has to be used).
Is this a bug in the browser implementations or are the code samples spread accross the internet crap??
Furthermore, is this setDate with positive and negative overflow secure to be used and uniformly implemented by all major browsers?
From MDN:
If the parameter you specify is outside of the expected range, setDate attempts to update the date information in the Date object accordingly. For example, if you use 0 for dayValue, the date will be set to the last day of the previous month.
It's logical if you think about it: setDate(1) sets the date to the first of the month. To get the last day of the previous month, that is, the day before the first of this month, you subtract one from the argument and get 0. If you subtract two days (1 - 2) you get the second to last day (-1).
are [..] code samples spread accross the internet crap?
Yes. This is true at least 90% of the time.
At MDN they say:
If the parameter you specify is outside of the expected range, setDate
attempts to update the date information in the Date object
accordingly. For example, if you use 0 for dayValue, the date will be
set to the last day of the previous month.
So you're getting coherent results:
1 - Jan 1
0 - Dec 31
-1 - Dec 30
-2 - Dec 29
Edit: It may look counter-intuitive if you think of it as a mere relative value, such as PHP's strtotime() function:
strtotime('-1 day');
It's not the case ;-)