Reputation: 12254
So I have a PHP variable w/ a (possibly the current, possibly not) month in it in the form of ##. If the month is less then October I want to take the leading 0 out. Is there a good and simple way to do this?
Upvotes: 0
Views: 6933
Reputation: 837
you can do it like:
<?php
$month = intval(Date('m'));
echo $month; // prints int value
?>
Upvotes: 0
Reputation: 1906
$today_mem = date("j.n");
Use j
instead of d
and n
instead of m:
source:: https://www.php.net/manual/en/function.date.php
Upvotes: 1
Reputation: 8509
<?php
$month = '05'; // May
$month *= 1;
echo $month;
?>
Output
5
Upvotes: 1
Reputation: 540
You can use the built in date function to do this, should look something like
<?php
date('n/d/Y',strtotime($dateVariable));
?>
You can use n instead of m to display the month without the leading zeros.
See http://php.net/manual/en/function.date.php for more information about date formatting.
Upvotes: 8
Reputation: 219804
Cast it as an integer:
<?php
$month = '01';
echo (int) $month; // prints 1
?>
Upvotes: 8