-3

I have string date value returned from database. Date is ="2015-06-26 13:23:04". How to add 200 minutes to this in javascript? I am not able to convert it to Date. I want same format.

I want to dispaly the same format "2015-06-26 13:23:04".

I used below code to convert.

 var datevar = "2015-06-26 13:23:04";
 var today = new Date(datevar).toISOString().slice(0, 20);

and i cant get correct hh:mm:ss value.

getting : "2015-06-26TO7:53:04"

Please help me. Thank you.

IMRUP
  • 1,463
  • 2
  • 11
  • 17
  • 1
    There are many questions about manipulating time in all coding languages. I suggest you do some serious research before asking questions. You may also want to read the [how to ask guide](http://stackoverflow.com/help/how-to-ask) to learn about what should be included in a good question such as an attempt. – Anonymous Jun 26 '15 at 11:49
  • I searched. I tried those solutions. but i didn't get any help. So i asked – IMRUP Jun 26 '15 at 11:51
  • possible duplicate of [Adding hours to Javascript Date object?](http://stackoverflow.com/questions/1050720/adding-hours-to-javascript-date-object) – Raúl Martín Jun 26 '15 at 11:51
  • @IMRUP Searching your exact title showed solutions, so I would suggest that you research more thoroughly. – Anonymous Jun 26 '15 at 11:54
  • Format is the problem. I cant get the same format. "2015-06-26 13:23:04". after adding also same format – IMRUP Jun 26 '15 at 11:57

1 Answers1

-1

If you are sure your string is like that, you can transform it into milliseconds and then add 20*60*1000 which corresponds to 20minuts

var yourString= "2015-06-26 13:23:04",
     year=yourString.substring(0,4),
     month=yourString.substring(5,7),
     day=yourString.substring(8,10),
     hour=yourString.substring(11,13),
     minuts=yourString.substring(14,16),
     secondes=yourString.substring(17,19),
     mkdate= new Date(year,month,day,hour,minuts,secondes),
     add200Minutes =mkdate.getTime() + 200*60*1000,
     newDate=new Date(add200Minutes);

     alert(newDate);
     
Bellash
  • 7,560
  • 6
  • 53
  • 86