Is there an easy way to change $month = "July";
so that $nmonth = 7
(07
would be fine too). I could do a case statement, but surely there is already a function to convert? EDIT: I wish I could accept multiple answers, cause two of you basically gave me what I needed by your powers combined.
$nmonth = date('m',strtotime($month));
That will give the numerical value for $month
. Thanks!
An alternative way to get a month number from an Excel date is using the TEXT function: =TEXT(A2, "m") - returns a month number without a leading zero, as 1 - 12. =TEXT(A2,"mm") - returns a month number with a leading zero, as 01 - 12.
Select the cells containing the month names that you want to convert. Press CTRL+1 from your keyboard or right-click and select “Format Cells” from the context menu that appears. This will open the Format Cells dialog box. Click on the Number tab and select “Custom” from the list under Category.
Using the & symbol joins the 1 to the first three characters of the cell or 1Sep. Excel recognises that as a date format and treats it like a date for the MONTH function to then extract the month number. Because if you type 1September it also returns a date.
Try this:
<?php $date = date_parse('July'); var_dump($date['month']); ?>
Yes,
$date = 'July 25 2010'; echo date('d/m/Y', strtotime($date));
The m
formats the month to its numerical representation there.
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