Monthly Archives: June 2014

How to add days in a date string using JavaScript ?

This is how you can add number of days in a date string using JavaScript.
In this example i have added 6 days in a date. Please check the demo.

	var someDate = new Date("2014-06-20");
	var numberOfDaysToAdd = 6; // add 6 days
	someDate.setDate(someDate.getDate() + numberOfDaysToAdd);

	var dd = someDate.getDate();
	var mm = someDate.getMonth() + 1;
	var y = someDate.getFullYear();

	var someFormattedDate = y +'-'+ mm +'-'+dd;
// output 2014-06-25

Another example using php.
You can add any number of days if you want to reduce number of days use minus(-) sign instead.


Demo

Share

How to Convert Seconds to Minute ?

There are 2 ways to convert Seconds into minute. Its super simple.

One - 
$seconds = "110";
$minutes = floor($seconds/60);
$secondsleft = $seconds%60;
if($minutes<10)
    $minutes = "0" . $minutes;
if($secondsleft<10)
    $secondsleft = "0" . $secondsleft;
echo "$minutes:$secondsleft Sec";
echo "
"; Two - echo gmdate("i.s", $seconds);
Share