Do the return conversion to integer type:
$mesAtual = (int) date("m");
In this way, var_dump
will result in:
int(6)
If you prefer, you can use the intval
$mesAtual = intval(date("m"));
This function has a second parameter that defines the numerical basis of the result. By default it is 10 and so in this case it does not have to be specified. A basic test using microtimes differences indicates that doing only the type cast is faster than calling the function (in Ideone it showed / strong> faster).
define("START", microtime(TRUE));
$mesAtual = intval(date("m"));
define("MIDDLE", microtime(TRUE));
$mesAtual = (int) date("m");
define("END", microtime(TRUE));
echo "intval: ", MIDDLE - START, PHP_EOL;
echo "type cast: ", END - MIDDLE, PHP_EOL;
Result:
intval: 0.043507099151611
type cast: 3.814697265625E-6
See working at Ideone .
Just use n
instead of m
, according to the documentation :
Numeric representation of a month, without zero left
Therefore:
$mesAtual = date('n');
var_dump($mesAtual);
// = string(1) "6"
It will be enough, so the representation will be from 1 to 12, instead of 01 to 12 .
Using Regular Expression example - ideone
$stt = strftime('%m', strtotime("06/04/2017"));
echo preg_replace('/0(\d)/', '$1', $stt);