Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert month number to month short name

Tags:

php

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

like image 238
Elitmiar Avatar asked May 31 '10 11:05

Elitmiar


People also ask

How do you convert month number to 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.

How do I get month name to month number in SQL?

In SQL Server, you can use the MONTH() function to convert a month name to its corresponding number.

How do you convert a month number to month name in tableau?

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.

How do I convert a number to a month in Excel?

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.


1 Answers

Append "01" and strtotime will be able to parse the string :

echo date('M', strtotime($month . '01'));
like image 146
mexique1 Avatar answered Oct 19 '22 23:10

mexique1