1

How can i trim down date from this Fri Oct 31 2014 01:00:00 GMT+0100 (Västeuropa, normaltid) to this 2014-10-31 on my get_fieldValues i think i can use

.setDate.getDate()+ 1).toISOString().substr(0, 10);

this is my fieldValues string

$('#GEN_4').val(fieldV.GEN_4_File_Prio);

have tried some combinations but didn't get it to work

enter image description here

Tried this should i really have to use Fri Oct 31 2014 01:00:00 GMT+0100 (Västeuropa, normaltid)

var d = new Date;

$('#GEN_4').val((fieldV.GEN_4_File_Prio.d.getFullYear() + '-' + d.getMonth()+1 + '-' + d.getDate()));

var d = new Date($('#GEN_4').val(fieldV.GEN_4_File_Prio));


$('#GEN_4').d.getFullYear() + '-' + d.getMonth()+1 + '-' + d.getDate();

UPDATE 2 Don't get it to work

enter image description here

3
  • Have you tried moment.js ?
    – eirikb
    Nov 3, 2014 at 12:47
  • You should pass the get_fieldValues date value to the new Date(..); object Nov 3, 2014 at 13:00
  • var d = new Date($('#GEN_4').val(fieldV.GEN_4_File_Prio)); like this? Nov 3, 2014 at 13:01

2 Answers 2

2

Try this

var d = new Date('Fri Oct 31 2014 01:00:00 GMT+0100 (Västeuropa, normaltid)');
alert(d.getFullYear() + '-' + d.getMonth()+1 + '-' + d.getDate());

Updated based on comment

//Assuming fieldV.GEN_4_File_Prio has a valid date string
var d = new Date(fieldV.GEN_4_File_Prio);
$('#GEN_4').val(d.getFullYear() + '-' + d.getMonth()+1 + '-' + d.getDate());
10
  • that worked but i needs to be plus 1 hour so it can work in both sweden and finland Nov 3, 2014 at 12:52
  • and it's shows 2014-9-31 but it should be 2014-10-31 Nov 3, 2014 at 12:53
  • getMonth() starts at 0, for the fun of it. Just do ` + (d.getMonth() + 1) + ...`. Note the parentheses here, they are important.
    – eirikb
    Nov 3, 2014 at 12:54
  • @linkan94 i have updated the answer Nov 3, 2014 at 12:54
  • don't get it to work is this rigth o near right var d = new Date; $('#GEN_4').val((fieldV.GEN_4_File_Prio.d.getFullYear() + '-' + d.getMonth()+1 + '-' + d.getDate())); Nov 3, 2014 at 12:57
0

This worked for me:

var d = fieldV.GEN_4_File_Prio;
d.setDate(d.getDate() + 1);

$('#GEN_4').val(d.toISOString().substr(0, 10));
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.