Get date from IE in UK format
up vote
0
down vote
favorite
In my html document I have a date field:
<input type="date" id="birthDate" class="date-picker">
I get this date in javascript like so:
var birthdate = new Date($('#birthDate').val());
and do some sums:
var today = new Date(Date.now());
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var bornDays = Math.floor(Math.abs((today.getTime() - birthdate.getTime()) / (oneDay)));
The user enters a date in DD/MM/YYYY format on the html page. In Chrome this works fine and gives me the correct number of days since birth 'bornDays'. IE however appears to interpret the entered date as being US format, i.e. MM/DD/YYYY so when I get the date into javascript it thinks the days are months and vice versa.
How can I specify that the date is in UK format when getting it from IE?
EXTRA CLARIFICATION:
If the user enters a date 09/11/2018 in the browser
In Chrome, birthdate.getDate() returns 9
In IE,birthdate.getDate() returns 11
javascript html date
add a comment |
up vote
0
down vote
favorite
In my html document I have a date field:
<input type="date" id="birthDate" class="date-picker">
I get this date in javascript like so:
var birthdate = new Date($('#birthDate').val());
and do some sums:
var today = new Date(Date.now());
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var bornDays = Math.floor(Math.abs((today.getTime() - birthdate.getTime()) / (oneDay)));
The user enters a date in DD/MM/YYYY format on the html page. In Chrome this works fine and gives me the correct number of days since birth 'bornDays'. IE however appears to interpret the entered date as being US format, i.e. MM/DD/YYYY so when I get the date into javascript it thinks the days are months and vice versa.
How can I specify that the date is in UK format when getting it from IE?
EXTRA CLARIFICATION:
If the user enters a date 09/11/2018 in the browser
In Chrome, birthdate.getDate() returns 9
In IE,birthdate.getDate() returns 11
javascript html date
stackoverflow.com/questions/7372038/…
– mplungjan
13 hours ago
$(".selector" ).datepicker( dateFormat: 'dd/mm/yyyy' );
Link
– R. García
13 hours ago
@R.García but that is not the HTML5 one
– mplungjan
13 hours ago
@mplungjan Doesn't it make sense ?
– R. García
13 hours ago
@R.García No, not really. That question was asking about a jQuery DatePicker. This one isn't. Furthermore this is why you should not answer questions in the comments section as it cannot be properly peer reviewed when wrong.
– Lightness Races in Orbit
13 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
In my html document I have a date field:
<input type="date" id="birthDate" class="date-picker">
I get this date in javascript like so:
var birthdate = new Date($('#birthDate').val());
and do some sums:
var today = new Date(Date.now());
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var bornDays = Math.floor(Math.abs((today.getTime() - birthdate.getTime()) / (oneDay)));
The user enters a date in DD/MM/YYYY format on the html page. In Chrome this works fine and gives me the correct number of days since birth 'bornDays'. IE however appears to interpret the entered date as being US format, i.e. MM/DD/YYYY so when I get the date into javascript it thinks the days are months and vice versa.
How can I specify that the date is in UK format when getting it from IE?
EXTRA CLARIFICATION:
If the user enters a date 09/11/2018 in the browser
In Chrome, birthdate.getDate() returns 9
In IE,birthdate.getDate() returns 11
javascript html date
In my html document I have a date field:
<input type="date" id="birthDate" class="date-picker">
I get this date in javascript like so:
var birthdate = new Date($('#birthDate').val());
and do some sums:
var today = new Date(Date.now());
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var bornDays = Math.floor(Math.abs((today.getTime() - birthdate.getTime()) / (oneDay)));
The user enters a date in DD/MM/YYYY format on the html page. In Chrome this works fine and gives me the correct number of days since birth 'bornDays'. IE however appears to interpret the entered date as being US format, i.e. MM/DD/YYYY so when I get the date into javascript it thinks the days are months and vice versa.
How can I specify that the date is in UK format when getting it from IE?
EXTRA CLARIFICATION:
If the user enters a date 09/11/2018 in the browser
In Chrome, birthdate.getDate() returns 9
In IE,birthdate.getDate() returns 11
javascript html date
javascript html date
edited 13 hours ago
asked 13 hours ago
Steve W
4621617
4621617
stackoverflow.com/questions/7372038/…
– mplungjan
13 hours ago
$(".selector" ).datepicker( dateFormat: 'dd/mm/yyyy' );
Link
– R. García
13 hours ago
@R.García but that is not the HTML5 one
– mplungjan
13 hours ago
@mplungjan Doesn't it make sense ?
– R. García
13 hours ago
@R.García No, not really. That question was asking about a jQuery DatePicker. This one isn't. Furthermore this is why you should not answer questions in the comments section as it cannot be properly peer reviewed when wrong.
– Lightness Races in Orbit
13 hours ago
add a comment |
stackoverflow.com/questions/7372038/…
– mplungjan
13 hours ago
$(".selector" ).datepicker( dateFormat: 'dd/mm/yyyy' );
Link
– R. García
13 hours ago
@R.García but that is not the HTML5 one
– mplungjan
13 hours ago
@mplungjan Doesn't it make sense ?
– R. García
13 hours ago
@R.García No, not really. That question was asking about a jQuery DatePicker. This one isn't. Furthermore this is why you should not answer questions in the comments section as it cannot be properly peer reviewed when wrong.
– Lightness Races in Orbit
13 hours ago
stackoverflow.com/questions/7372038/…
– mplungjan
13 hours ago
stackoverflow.com/questions/7372038/…
– mplungjan
13 hours ago
$(".selector" ).datepicker( dateFormat: 'dd/mm/yyyy' );
Link– R. García
13 hours ago
$(".selector" ).datepicker( dateFormat: 'dd/mm/yyyy' );
Link– R. García
13 hours ago
@R.García but that is not the HTML5 one
– mplungjan
13 hours ago
@R.García but that is not the HTML5 one
– mplungjan
13 hours ago
@mplungjan Doesn't it make sense ?
– R. García
13 hours ago
@mplungjan Doesn't it make sense ?
– R. García
13 hours ago
@R.García No, not really. That question was asking about a jQuery DatePicker. This one isn't. Furthermore this is why you should not answer questions in the comments section as it cannot be properly peer reviewed when wrong.
– Lightness Races in Orbit
13 hours ago
@R.García No, not really. That question was asking about a jQuery DatePicker. This one isn't. Furthermore this is why you should not answer questions in the comments section as it cannot be properly peer reviewed when wrong.
– Lightness Races in Orbit
13 hours ago
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
If you know that the string entered will be in DD-MM-YYYY form, parse it and hand its individual components to the Date
constructor rather than hoping the Date
constructor will be able to guess at the input format.
Or, better yet, provide separate fields for day/month/year (or a calendar widget) so that you're not reliant on users to type a specifically-formatted string.
add a comment |
up vote
0
down vote
Could you store each part of the data - day, month and year in variables and then construct a string in the order you desire? That should work in all browsers.
var currentTime = new Date();
var gmt = new Date(currentTime.valueOf() + currentTime.getTimezoneOffset() * 60000);
var day = gmt.getDate();
var month = gmt.getMonth() + 1;
var year = gmt.getFullYear();
var dateString = day + '/' + month + '/' + year;
No, because getDate() returns the month value when in IE
– Steve W
13 hours ago
getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
– SPlatten
13 hours ago
What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
– Steve W
12 hours ago
Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
– James Howell
11 hours ago
add a comment |
up vote
0
down vote
To avoid various different interpretations in Date / Time, in various different browsers, it is encouraged to use a librabry such as MomentJS.
Now, let's say you need to get the date
out of a string.
var day = moment("1995-12-25");
moment().date(); //will gives you the date
The above will give you the same answer across all browsers.
MomentJS supports following browsers,
Currently the following browsers are used for the ci system: Chrome on Windows XP, IE 8, 9, and 10 on Windows 7, IE 11 on Windows 10, latest Firefox on Linux, and latest Safari on OSX 10.8 and 10.11.
I hope you will find this answer helpful.
Cheers.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If you know that the string entered will be in DD-MM-YYYY form, parse it and hand its individual components to the Date
constructor rather than hoping the Date
constructor will be able to guess at the input format.
Or, better yet, provide separate fields for day/month/year (or a calendar widget) so that you're not reliant on users to type a specifically-formatted string.
add a comment |
up vote
0
down vote
If you know that the string entered will be in DD-MM-YYYY form, parse it and hand its individual components to the Date
constructor rather than hoping the Date
constructor will be able to guess at the input format.
Or, better yet, provide separate fields for day/month/year (or a calendar widget) so that you're not reliant on users to type a specifically-formatted string.
add a comment |
up vote
0
down vote
up vote
0
down vote
If you know that the string entered will be in DD-MM-YYYY form, parse it and hand its individual components to the Date
constructor rather than hoping the Date
constructor will be able to guess at the input format.
Or, better yet, provide separate fields for day/month/year (or a calendar widget) so that you're not reliant on users to type a specifically-formatted string.
If you know that the string entered will be in DD-MM-YYYY form, parse it and hand its individual components to the Date
constructor rather than hoping the Date
constructor will be able to guess at the input format.
Or, better yet, provide separate fields for day/month/year (or a calendar widget) so that you're not reliant on users to type a specifically-formatted string.
answered 13 hours ago
Lightness Races in Orbit
277k50445756
277k50445756
add a comment |
add a comment |
up vote
0
down vote
Could you store each part of the data - day, month and year in variables and then construct a string in the order you desire? That should work in all browsers.
var currentTime = new Date();
var gmt = new Date(currentTime.valueOf() + currentTime.getTimezoneOffset() * 60000);
var day = gmt.getDate();
var month = gmt.getMonth() + 1;
var year = gmt.getFullYear();
var dateString = day + '/' + month + '/' + year;
No, because getDate() returns the month value when in IE
– Steve W
13 hours ago
getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
– SPlatten
13 hours ago
What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
– Steve W
12 hours ago
Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
– James Howell
11 hours ago
add a comment |
up vote
0
down vote
Could you store each part of the data - day, month and year in variables and then construct a string in the order you desire? That should work in all browsers.
var currentTime = new Date();
var gmt = new Date(currentTime.valueOf() + currentTime.getTimezoneOffset() * 60000);
var day = gmt.getDate();
var month = gmt.getMonth() + 1;
var year = gmt.getFullYear();
var dateString = day + '/' + month + '/' + year;
No, because getDate() returns the month value when in IE
– Steve W
13 hours ago
getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
– SPlatten
13 hours ago
What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
– Steve W
12 hours ago
Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
– James Howell
11 hours ago
add a comment |
up vote
0
down vote
up vote
0
down vote
Could you store each part of the data - day, month and year in variables and then construct a string in the order you desire? That should work in all browsers.
var currentTime = new Date();
var gmt = new Date(currentTime.valueOf() + currentTime.getTimezoneOffset() * 60000);
var day = gmt.getDate();
var month = gmt.getMonth() + 1;
var year = gmt.getFullYear();
var dateString = day + '/' + month + '/' + year;
Could you store each part of the data - day, month and year in variables and then construct a string in the order you desire? That should work in all browsers.
var currentTime = new Date();
var gmt = new Date(currentTime.valueOf() + currentTime.getTimezoneOffset() * 60000);
var day = gmt.getDate();
var month = gmt.getMonth() + 1;
var year = gmt.getFullYear();
var dateString = day + '/' + month + '/' + year;
edited 11 hours ago
answered 13 hours ago
James Howell
3222822
3222822
No, because getDate() returns the month value when in IE
– Steve W
13 hours ago
getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
– SPlatten
13 hours ago
What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
– Steve W
12 hours ago
Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
– James Howell
11 hours ago
add a comment |
No, because getDate() returns the month value when in IE
– Steve W
13 hours ago
getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
– SPlatten
13 hours ago
What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
– Steve W
12 hours ago
Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
– James Howell
11 hours ago
No, because getDate() returns the month value when in IE
– Steve W
13 hours ago
No, because getDate() returns the month value when in IE
– Steve W
13 hours ago
getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
– SPlatten
13 hours ago
getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
– SPlatten
13 hours ago
What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
– Steve W
12 hours ago
What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
– Steve W
12 hours ago
Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
– James Howell
11 hours ago
Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
– James Howell
11 hours ago
add a comment |
up vote
0
down vote
To avoid various different interpretations in Date / Time, in various different browsers, it is encouraged to use a librabry such as MomentJS.
Now, let's say you need to get the date
out of a string.
var day = moment("1995-12-25");
moment().date(); //will gives you the date
The above will give you the same answer across all browsers.
MomentJS supports following browsers,
Currently the following browsers are used for the ci system: Chrome on Windows XP, IE 8, 9, and 10 on Windows 7, IE 11 on Windows 10, latest Firefox on Linux, and latest Safari on OSX 10.8 and 10.11.
I hope you will find this answer helpful.
Cheers.
add a comment |
up vote
0
down vote
To avoid various different interpretations in Date / Time, in various different browsers, it is encouraged to use a librabry such as MomentJS.
Now, let's say you need to get the date
out of a string.
var day = moment("1995-12-25");
moment().date(); //will gives you the date
The above will give you the same answer across all browsers.
MomentJS supports following browsers,
Currently the following browsers are used for the ci system: Chrome on Windows XP, IE 8, 9, and 10 on Windows 7, IE 11 on Windows 10, latest Firefox on Linux, and latest Safari on OSX 10.8 and 10.11.
I hope you will find this answer helpful.
Cheers.
add a comment |
up vote
0
down vote
up vote
0
down vote
To avoid various different interpretations in Date / Time, in various different browsers, it is encouraged to use a librabry such as MomentJS.
Now, let's say you need to get the date
out of a string.
var day = moment("1995-12-25");
moment().date(); //will gives you the date
The above will give you the same answer across all browsers.
MomentJS supports following browsers,
Currently the following browsers are used for the ci system: Chrome on Windows XP, IE 8, 9, and 10 on Windows 7, IE 11 on Windows 10, latest Firefox on Linux, and latest Safari on OSX 10.8 and 10.11.
I hope you will find this answer helpful.
Cheers.
To avoid various different interpretations in Date / Time, in various different browsers, it is encouraged to use a librabry such as MomentJS.
Now, let's say you need to get the date
out of a string.
var day = moment("1995-12-25");
moment().date(); //will gives you the date
The above will give you the same answer across all browsers.
MomentJS supports following browsers,
Currently the following browsers are used for the ci system: Chrome on Windows XP, IE 8, 9, and 10 on Windows 7, IE 11 on Windows 10, latest Firefox on Linux, and latest Safari on OSX 10.8 and 10.11.
I hope you will find this answer helpful.
Cheers.
answered 11 hours ago
Anjana Silva
1,96712128
1,96712128
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224050%2fget-date-from-ie-in-uk-format%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
stackoverflow.com/questions/7372038/…
– mplungjan
13 hours ago
$(".selector" ).datepicker( dateFormat: 'dd/mm/yyyy' );
Link– R. García
13 hours ago
@R.García but that is not the HTML5 one
– mplungjan
13 hours ago
@mplungjan Doesn't it make sense ?
– R. García
13 hours ago
@R.García No, not really. That question was asking about a jQuery DatePicker. This one isn't. Furthermore this is why you should not answer questions in the comments section as it cannot be properly peer reviewed when wrong.
– Lightness Races in Orbit
13 hours ago