Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add hours to a parse moment date?

I just want to ask if it is possible to add hours to a parse moment date. I have a code like this:

var myDate = "2017-04-14 07:07:15"; 
var object_myDate = moment(myDate).format('YYYY-MM-DD hh:mm:ss');
var status = object_myDate.add(5, 'hours');

but this code gives the following error:

object_myDate.add is not a function
like image 300
Arnold wanna be Avatar asked Apr 14 '17 07:04

Arnold wanna be


People also ask

How do I add hours to a date in a moment?

add(Duration); moment(). add(Object); Mutates the original moment by adding time. This is a pretty robust function for adding time to an existing moment.

How do you add 30 days in a moment?

moment(). add(30, 'days');

How do you add minutes to a moment?

add(minutes, 'minutes') . format('LTS');


1 Answers

add is a moment function, you should use on moment object:

var myDate = "2017-04-14 07:07:15"; 
var status = moment(myDate).add(5, 'hours').format('YYYY-MM-DD hh:mm:ss');
like image 181
VincenzoC Avatar answered Oct 21 '22 09:10

VincenzoC