Xaver
Xaver

Reputation: 11662

How to get seconds from a timestrong

I like to get the seconds from a string like 11.5 years. Using strtotime() return a negative value

strtotime('11.5 years', 0)

which is explained here

Upvotes: 0

Views: 47

Answers (3)

Xaver
Xaver

Reputation: 11662

I came up with this solution which works for my application

$value = 11.5;
$unit = 'year'; //day, second, month,...

$integer = floor($value);
$decimal = $value-$integer;

               //get value of full [unit] and at the percentage from the decmail
$delay = strtotime('+'.$integer.' '.$unit, 0)+strtotime('+1 '.$unit, 0)*$decimal

Upvotes: 0

Rahul Tripathi
Rahul Tripathi

Reputation: 172438

You may try this:

echo strtotime('+11 years 6 months');

Upvotes: 1

Hanky Panky
Hanky Panky

Reputation: 46900

echo strtotime('+11 years 6 months');

Fiddle

Upvotes: 2

Related Questions