Reputation: 83
I have bulgarian short date pattern string from calendar control how can I create date object without removing 'г.' from it.
new Date('26.6.2015 г.')
I wanted to compare the date selected from calender with today's date
if (($.datepicker.formatDate('yy/mm/dd', new Date()))
($.datepicker.formatDate('yy/mm/dd', new Date('26.6.2015 г.'))))
{ alert('success')}
Upvotes: 1
Views: 44
Reputation: 3847
this might help you .
var stringDate='26.6.2015 г.';// assuming this the format you get and used regex to match this pattern
stringDate=stringDate.substring(0, stringDate.indexOf(' '));// to remove everything after space including space
var pattern = /^(\d{1,2})\.(\d{1,2})\.(\d{4})$/;
var arrayDate = stringDate.match(pattern);
var dt = new Date(arrayDate[3], arrayDate[2] - 1, arrayDate[1]);
console.log(dt)// this is date object
Upvotes: 0