I have a variable with the following value
$month = 201002;
the first 4 numbers represent the year, and the last 2 numbers represent the month. I need to get the last 2 numbers in the month string name eg. Feb
My code looks like this
<?php echo date('M',substr($month,4,6)); ?>
I can I go about to obtain the month name
Please do as follows: Select a blank cell next to the sales table, type the formula =TEXT(A2*29,"mmm") (Note: A2 is the first number of the Month list you will convert to month name), and then drag the AutoFill Handle down to other cells. Now you will see the numbers (from 1 to 12) are converted to normal month names.
In SQL Server, you can use the MONTH() function to convert a month name to its corresponding number.
So one way to do this is to turn the 'Date Month' into a date, and then use the datename function to get the month name.
In case you want to get a month name rather than a number, you use the TEXT function in Excel. =TEXT(A2,mmmm)- returns a full month name, as January - December.
Append "01" and strtotime will be able to parse the string :
echo date('M', strtotime($month . '01'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With