strtotime,floor,abs,ceil functions in PHP


strtotime():- This function converts and English text DateTime into a unique timestamp but we have to wrap the result using this date format date(‘Y-m-d’) to avoid the errors. For example

<?php
	 $date = '1 January 2020';
      echo date('Y-m-d',strtotime($date));
?>

The output is 2020-01-01

floor():- This function returns a number down to its nearest integer. For example

<?php
      echo floor(0.30).'<br>';
      echo floor(3).'<br>';
      echo floor(3.3).'<br>';
      echo floor(-3.3).'<br>';
?>

The output will be like this----

  0
  3
  3
  -4

Ceil():- This function returns a number up to its nearest integer. For example:-

<?php
      echo ceil(0.30).'<br>';
      echo ceil(3).'<br>';
      echo ceil(3.3).'<br>';
      echo ceil(-3.3).'<br>';
?>

The output will be like this----

  1
  3
  4
 -3

abs():- This function is an inbuilt PHP function that always returns a positive(+ve) or absolute number of any data type like integer, float, double etc. For example-

<?php
      echo abs(3).'<br>';
      echo abs(-3).'<br>';
      echo abs(3.3).'<br>';
      echo abs(-3.4).'<br>';
?>

The output will be like this------

3
3
3.3
3.4

Conclusion:- I hope this tutorial will help you to understand the strtotime(), floor(),abs() and ceil() functions in PHP.

Also Read, PHP Difference Between Two Dates In Years, Months And Days


2 thoughts on “strtotime,floor,abs,ceil functions in PHP”

Leave a Comment