0

I want to enter the full name of the month and in response i want to get the number of the month. i have tried following code, when i pass the "March" as month name it return me "1".is there any way to get the number of the month in php?

$month_number = date('n', strtotime($string));
usman khalid
  • 75
  • 3
  • 14
  • That code returns "1" for January or _any unrecognised string_ that's passed into `strtotime`. It successfully returns "3" if I pass "March" as `$string` to your code. – Dan Abrey Mar 01 '16 at 13:27

2 Answers2

1

Try this :

<?php
  $date = date_parse('March');
  echo($date['month']);
?>

May this will help you :)

RK12
  • 472
  • 3
  • 11
0

Try:

date('m', strtotime("March"));
Tobias
  • 653
  • 4
  • 12
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Justin Howard Mar 01 '16 at 16:28